TheDProgrammer TheDProgrammer - 1 year ago 34
SQL Question

How to subtract Time Column from DateTime Column in SQL?

I have

column which is a
Column. I want to subtract the value in the
column from
Column and return a new column with the
Value in it. My sample data is like this:

States crea_date IST
AB 2014-12-30 15:01:00.000 12:30:00.0000000
AK 2014-12-29 16:32:00.000 10:30:00.0000000
AZ 2014-12-18 16:07:00.000 11:30:00.0000000

Thanks in Advance

0xF 0xF
Answer Source

If IST is an integer number of seconds:

SELECT DATEADD(s, -IST, crea_date)
FROM yourTable

If IST is of the TIME type:

SELECT DATEADD(ms, DATEDIFF(ms, IST, '00:00:00'), crea_date)
FROM yourTable