MySQL:如何在查询中的日期时间字段中添加一天 [英] MySQL: How to add one day to datetime field in query

查看:2459
本文介绍了MySQL:如何在查询中的日期时间字段中添加一天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的表中,我有一个名为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屋!

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