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
How about this?
SELECT (fields)
FROM dbo.YourTable
WHERE DATEPART(HOUR, MyDate) >= 12
AND DATEPART(MINUTE, MyDate) >= 23
AND DATEPART(SECOND, MyDate) >= 45
The hour is given in the 24-hour format, e.g. 12 means 12 hour noon, 15 means 3pm.
DATEPART also has "parts" for minutes, seconds and so forth. You can of course use as many of those date parts in your WHERE clause as you like.