Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get date Minus 1 day but at exacty 4 AM

I have the following sql server WHERE clause:

WHERE (DateCreated >= CONVERT(datetime, GETDATE(), 111) - 1)

This gets the date (where today is 2015-06-09) 2015-06-08. I need to add a time to this as well like 2015-06-08 04:00:00 in 24H format. the time will always be the same bat every time the SQL command is executed, it should only be from yesterday at 4 AM to the current date and time.

how can this be achieved?

like image 586
Steven de Beer Avatar asked Mar 16 '23 19:03

Steven de Beer


1 Answers

Try this:

WHERE DateCreated >= dateadd(d, datediff(d, 1, getdate()), '04:00')
like image 107
t-clausen.dk Avatar answered Mar 24 '23 21:03

t-clausen.dk