MySQL: 如何在查询中向 datetime 字段添加一天

在我的表中,我有一个 datetime格式的 eventdate字段,比如 2010-05-11 00:00:00

我如何做一个查询,以便它添加到 eventdate总有一天,例如,如果今天是 2010-05-11,我想在 where子句中显示返回的所有记录与明天的日期。

更新:

我试过了:

Select * from fab _ Scheder where custid = 1334666058 and DATE _ ADD (eventdate,INTERVAL 1 DAY)

但不幸的是,即使我加上大于1的间隔,它也返回相同的记录。

结果:

2010-05-12 00:00:00

但我只想选明天的唱片。

143702 次浏览
$date = strtotime(date("Y-m-d", strtotime($date)) . " +1 day");

Or, simplier:

date("Y-m-d H:i:s", time()+((60*60)*24));

You can use the DATE_ADD() function:

... WHERE DATE(DATE_ADD(eventdate, INTERVAL -1 DAY)) = CURRENT_DATE

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)

Have a go with this, as this is how I would do it :)

SELECT *
FROM fab_scheduler
WHERE custid = '123456'
AND CURDATE() = DATE(DATE_ADD(eventdate, INTERVAL 1 DAY))

It`s possible to use MySQL specific syntax sugar:

SELECT ... date_field + INTERVAL 1 DAY

Looks much more pretty instead of DATE_ADD function

How about this: 

select * from fab_scheduler where custid = 1334666058 and eventdate = eventdate + INTERVAL 1 DAY

If you are able to use NOW() this would be simplest form:

SELECT * FROM `fab_scheduler` WHERE eventdate>=(NOW() - INTERVAL 1 DAY)) AND eventdate<NOW() ORDER BY eventdate DESC;

With MySQL 5.6+ query abowe should do. Depending on sql server, You may be required to use CURRDATE() instead of NOW() - which is alias for DATE(NOW()) and will return only date part of datetime data type;

You can try this:

SELECT DATE(DATE_ADD(m_inv_reqdate, INTERVAL + 1 DAY)) FROM  tr08_investment