I have a table of events, constantly being updated, with a datetime column.
I want to get all events that start today as well as the ones that start 8 hours into the next day.
The idea is that people don’t really check in the middle of the night for events, so we list them in the day before.
To get today’s I do DATEDIFF(day,eventdate,GETDATE())=0 but I havn’t figured out how to do the dateadd() for my case. I either get no rows or too many.
So the wanted result is:
From 00:00 on March 9 to 8:00 on March 10. (example only)
It is better to not do any calculation on your column. Calculate the interval instead and fetch the rows that is in the interval. That way you can make use of a index on
eventdateinstead of doing a table scan.