How can I compare only the time portion of a DateTime data type in SQL Server 2005? For example, I want to get all records in which MyDateField is after a specific time. The
Here's the SQL to match date with time:
to match only time:
AND CAST(RIGHT(CONVERT(VARCHAR, YOURDATE, 100), 7) as time) >
CAST(RIGHT(CONVERT(VARCHAR, GETDATE(), 100), 7) as time)
to match date with time:
CAST(YOURDATE AS DATE)=CAST(GETDATE() AS DATE)
AND CAST(RIGHT(CONVERT(VARCHAR, YOURDATE, 100), 7) as time) >
CAST(RIGHT(CONVERT(VARCHAR, GETDATE(), 100), 7) as time)