How can I use the SQL DATEADD() function to find a record from this business day? For example:
SELECT * FROM records r
WHERE r.creationTime <= GETDATE()
AND r.creationTime >= DATEADD(dd, -1 * hoursFromStartOfThisDay, GETDATE())
Where ‘hoursFromStartOfThisDay’ is exactly what it says.
Note: I’m talking about business days so from 9am-5pm, Monday-Friday if that matters at all.
Thanks, guys!
Edit: I am also looking to apply a solution to this for the start of the beginning of the week/month and maybe hour too.
Edit: So if a record was created at 18/07/2011 08:55:00 and another created at 18/07/2011 09:05:00, I want the second record to be picked up by the query and not the first. However if the current GETDATE() is 18/07/2011 09:15:00 then it gets tricky.
how about adding AND r.creationTime >= '9am'?
Are you really need a
hoursFromStartOfThisDayvariable?If your day is static, from 9 to 5, you can use just this static range: