MySQL:如何在查询中的日期时间字段中添加一天 [英] MySQL: How to add one day to datetime field in query
问题描述
在我的表中,我有一个名为eventdate
的字段,格式为datetime
,例如2010-05-11 00:00:00
.
In my table I have a field named eventdate
in datetime
format like 2010-05-11 00:00:00
.
我如何进行查询,以便将一天添加到eventdate
,例如,如果今天是2010-05-11
,我想在where
子句中显示以返回明天所有的记录日期.
How do i make a query so that it adds one day to the eventdate
eg if today is 2010-05-11
, i want to show in where
clause to return all records with tomorrow's date.
更新:
我尝试过:
select * from fab_scheduler where custid = 1334666058 and DATE_ADD(eventdate, INTERVAL 1 DAY)
select * from fab_scheduler where custid = 1334666058 and DATE_ADD(eventdate, INTERVAL 1 DAY)
但是不幸的是,即使我添加的间隔大于1,它也会返回相同的记录.
But unfortunately it returns the same record even if i add an interval greater than 1.
结果:
2010-05-12 00:00:00
但是我只想选择带有明天日期的记录.
But i only want to select records with tomorrow's date.
推荐答案
You can use the DATE_ADD()
function:
... WHERE DATE(DATE_ADD(eventdate, INTERVAL -1 DAY)) = CURRENT_DATE
它也可以在SELECT
语句中使用:
It can also be used in the SELECT
statement:
SELECT DATE_ADD('2010-05-11', INTERVAL 1 DAY) AS Tomorrow;
+------------+
| Tomorrow |
+------------+
| 2010-05-12 |
+------------+
1 row in set (0.00 sec)
这篇关于MySQL:如何在查询中的日期时间字段中添加一天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!