I found an article by Gregory Larsen called Working with SQL Server Date/Time Variables: Part Three - Searching for Particular Date Values and Ranges that helped me with a few different ways of verifying a date range I was trying to make sure included events scheduled for after today's date.
I'm sure there are more elegant ways of doing this, but I wanted to list all "upcoming" events which included events that may have already occured today (but have them fall off the list tomorrow). I went for the FLOOR approach with this code:
SELECT * FROM Events WHERE Event_Date >= CAST(FLOOR(CAST(GETDATE() AS FLOAT)) AS DATETIME)
I've always wished they had a slick date function that would just drop the seconds from a date for ease of comparison. Oh well.
No comments:
Post a Comment