David
David

Reputation: 4007

mysql NOW() with defined time

I need to perform a mysql select query where date time field in table is less then todays date with a time of 2am.

How would I structure this

SELECT * FROM tbl WHERE datetimefield < (DATE(NOW()) and time 2am)

Thank you for any assistance.

Upvotes: 1

Views: 68

Answers (2)

Madthew
Madthew

Reputation: 686

SELECT * FROM tbl WHERE datetimefield < STR_TO_DATE(concat(curdate(), ' ', '02'),'%Y-%m-%d %H')

Upvotes: 0

user4035
user4035

Reputation: 23749

This worked:

SELECT * FROM tbl WHERE datetimefield < DATE_ADD(CURDATE(), INTERVAL 2 HOUR)

fiddle - in the fiddle I used a hard coded date '2013-05-04', so it would work correctly later.

Upvotes: 3

Related Questions