在 MySQL 中按当前日期过滤 [英] Filter by current date in MySQL
本文介绍了在 MySQL 中按当前日期过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何像这样的查询一样将当前日期传递给 mysql 中的查询:
How to pass the current date to a query in mysql like such query:
select from Dailytimesheet dailytimesheet where dailytimesheet.TrackingDate="2010-05-03"
推荐答案
在 MySQL 中,您可以使用 CURRENT_DATE
获取当前日期.
In MySQL, you can use CURRENT_DATE
to get the current date.
mysql> select CURRENT_DATE;
+--------------+
| CURRENT_DATE |
+--------------+
| 2010-05-03 |
+--------------+
1 row in set (0.08 sec)
使用 NOW()
也能工作,但可以获取当前日期和时间作为时间戳值.您可以像 DATE(NOW())
那样截断它,但是 CURRENT_DATE
避免了函数调用.
Using NOW()
works as well, but gets you the current date and time as a timestamp value. You can truncate it like DATE(NOW())
, but CURRENT_DATE
avoids the function call.
这篇关于在 MySQL 中按当前日期过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文