Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL date comparison function

Tags:

date

mysql

In my table dates are stored in the format "2010-08-26 09:00:00" so yyyy-mm-dd. I'd like to select all fields that have a date field that is "today", so between 2010-08-26 00:00:01 and 2010-08-26 23:59:59.

Just using larger and smaller than operators does not work, does MySQL have some built in date comparison functions that can do this?

EDIT: I should have mentioned dates are stored as datetime fields

like image 858
stef Avatar asked Mar 11 '26 13:03

stef


1 Answers

... WHERE DATE(field)=CURDATE()

or

... WHERE DATE(field)=CURRENT_DATE

or

... WHERE DATE(field)=CURRENT_DATE()

Pick one!

like image 77
Vili Avatar answered Mar 14 '26 05:03

Vili