MySQL compare now() (only date, not time) with a datetime field

Mysql

Mysql Problem Overview


I have a duedate column(datetime format) that specifies the due date of a ticket, now i need to get 'Due today' tickets base on the comparison between now() with duedate. i.e 2010-04-29 02:00 vs 2010-04-29 10:00 would return true in this matter.

Mysql Solutions


Solution 1 - Mysql

Use DATE(NOW()) to compare dates

DATE(NOW()) will give you the date part of current date and DATE(duedate) will give you the date part of the due date. then you can easily compare the dates

So you can compare it like

DATE(NOW()) = DATE(duedate)

OR

DATE(duedate) = CURDATE() 

See here

Solution 2 - Mysql

Compare date only instead of date + time (NOW) with:

CURDATE()

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1918956View Question on Stackoverflow
Solution 1 - MysqlBhavik ShahView Answer on Stackoverflow
Solution 2 - MysqlCae VecchiView Answer on Stackoverflow