Martin February 2016
SQL Server see which time is greater
I need to pull the time from a field in an existing table which is stored as SMALLDATETIME.
An example of the value stored is as follows:
Jun 4 1900 11:30AM
I need to grab the time part (hours and minutes) and see if it is less than whatever the current time is now.
EG IF @CutoffTime < @CurrentTime THEN
Is there an easy way to do this in SQL Server?
Jamie Pollard February 2016
You can cast the
datetime to a time, along with the time from
getutcdate(), and compare:
DECLARE @timeA SMALLDATETIME;
SET @timeA = 'Jun 4 1900 11:30AM'
IF CAST(@timeA AS TIME) < CAST(GETUTCDATE() AS TIME)
PRINT 'Time earlier than current time'
Asked in February 2016
Viewed 2,486 times
Answered 1 times
Leave an answer
Quote of the day: live life