all groups > sql server programming > october 2004 >
You're in the

sql server programming

group:

How to compare time of day only, for smallDatePart?


How to compare time of day only, for smallDatePart? wolfv
10/17/2004 8:57:01 PM
sql server programming:
Transact-SQL-Reference says:
SQL Server stores smalldatetime values as two 2-byte integers. The first 2
bytes store the number of days after January 1, 1900. The other 2 bytes store
the number of minutes since midnight.

Is there a way to compare just the time of day for smallDatePart?

DECLARE @minutesSinceMidnight1 smallDateTime,
@minutesSinceMidnight2 smallDateTime

If @minutesSinceMidnight1 < @minutesSinceMidnight2


Re: How to compare time of day only, for smallDatePart? Derrick Leggett
10/17/2004 11:57:06 PM
Have no idea why you would want to do this....but here goes:

DECLARE
@time1 SMALLDATETIME,
@time2 SMALLDATETIME

SELECT
@time1 = '01/01/04 10:59:00',
@time2 = '01/01/05 11:21:00'

SELECT DATEDIFF(mi,CONVERT(VARCHAR,@time1,108),CONVERT(VARCHAR,@time2,108))


[quoted text, click to view]

Re: How to compare time of day only, for smallDatePart? Adam Machanic
10/18/2004 12:46:02 AM

[quoted text, click to view]

Assuming you have the same value for the date part, you've just
compared only the time of day...

If the dates are different, here is one way to get the number of minutes
since midnight:

datediff(mm, dateadd(dd, 0, datediff(dd, @minutesSinceMidnight1 , 0)),
@minutesSinceMidnight1)

Re: How to compare time of day only, for smallDatePart? Adam Machanic
10/18/2004 1:01:02 AM

[quoted text, click to view]

That should have been 'mi', not 'mm'.

AddThis Social Bookmark Button