MySQL将now()(仅日期,而不是时间)与datetime字段进行比较 [英] MySQL compare now() (only date, not time) with a datetime field

查看:350
本文介绍了MySQL将now()(仅日期,而不是时间)与datetime字段进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个duedate列(datetime格式),它指定了票证的到期日,现在我需要根据now()duedate之间的比较来获取'Due today'票证.即2010-04-29 02:002010-04-29 10:00在此问题上将返回true.

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.

推荐答案

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

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

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)

DATE(duedate) = CURDATE() 

请参见此处

这篇关于MySQL将now()(仅日期,而不是时间)与datetime字段进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆