MySQL 将 now()(仅日期,而非时间)与日期时间字段进行比较

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14533914/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 16:19:30  来源:igfitidea点击:

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

mysql

提问by user1918956

I have a duedatecolumn(datetimeformat) 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:00vs 2010-04-29 10:00would return true in this matter.

我有一个duedate列(datetime格式)指定票的到期日,现在我需要根据now()duedate. 即2010-04-29 02:00vs2010-04-29 10:00在这件事上会返回 true 。

回答by Bhavik Shah

Use DATE(NOW())to compare dates

使用DATE(NOW())比较日期

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

DATE(NOW())将为您提供当前日期的日期部分,并DATE(duedate)为您提供到期日的日期部分。然后您可以轻松比较日期

So you can compare it like

所以你可以比较它像

DATE(NOW()) = DATE(duedate)

OR

或者

DATE(duedate) = CURDATE() 

See here

这里

回答by Cae Vecchi

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

仅比较日期而不是日期 + 时间 (NOW) 与:

CURDATE()