Question

I have a column that pulls in two dates, 1 of the dates has the correct date and time so I can easily compare the number of minutes between this date and GetDate() but some values have the date 01/01/1900 and then the time i need to use.

How can I do datediff but ignore the date and only use the times?

So

My date   | 01/01/1900 14:25:00
GetDate() | 06/02/2014 14:26:00

Would give me 1 minute

Was it helpful?

Solution

Convert your datetime to the time data type and then everything works as expected.

Ex:

Declare @d1 DateTime,
        @d2 DateTime

Select  @d1 = '01/01/1900 14:25:00',
        @d2 = '06/02/2014 14:26:00'

Select DATEDIFF(minute, Convert(Time, @d1), Convert(Time, @d2))

The time data type was added in SQL2008 (which you have tagged in your question).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top