Reputation: 201
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
Upvotes: 0
Views: 277
Reputation: 24498
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).
Upvotes: 3