MySQL: how to add one day to the datetime field in a query

In my table, I have a field named eventdate in datetime format, for example 2010-05-11 00:00:00 .

How to make a request so that it adds one day to the eventdate , for example, if today is 2010-05-11 , I want to show in the where clause in order to return all records from tomorrow date.

Update:

I tried this:

select * from fab_scheduler where custid = 1334666058 and DATE_ADD(eventdate, INTERVAL 1 DAY)

But unfortunately, it returns the same record, even if I add an interval greater than 1.

Result:

2010-05-12 00:00:00

But I only want to select entries with a date tomorrow.

+43
sql mysql
May 11 '10 at 12:11
source share
8 answers

You can use the DATE_ADD() function:

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

It can also be used in a SELECT :

 SELECT DATE_ADD('2010-05-11', INTERVAL 1 DAY) AS Tomorrow; +------------+ | Tomorrow | +------------+ | 2010-05-12 | +------------+ 1 row in set (0.00 sec) 
+86
May 11 '10 at
source share
 SELECT DATE_ADD(eventdate, INTERVAL 1 DAY) 

Mysql doc

+11
May 11 '10 at 12:14
source share

Go with this, as I will do it :)

 SELECT * FROM fab_scheduler WHERE custid = '123456' AND CURDATE() = DATE(DATE_ADD(eventdate, INTERVAL 1 DAY)) 
+4
May 11 '10 at
source share

If you can use NOW (), this will be the simplest form:

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

With MySQL 5.6+, the abowe query should be executed. Depending on the sql server, you may need to use CURRDATE() instead of NOW() - which is an alias for DATE(NOW()) and will only return a date in the datetime type;

+1
Jan 11 '16 at 8:35
source share

You can use MySQL special syntactic sugar:

 SELECT ... date_field + INTERVAL 1 DAY 

It looks much prettier instead of the DATE_ADD function

0
May 11 '10 at 16:43
source share

How about this:

 select * from fab_scheduler where custid = 1334666058 and eventdate = eventdate + INTERVAL 1 DAY 
0
Oct. 15 '14 at 8:50
source share

You can try the following:

 SELECT DATE(DATE_ADD(m_inv_reqdate, INTERVAL + 1 DAY)) FROM tr08_investment 
0
Nov 16 '16 at 9:49
source share
 $date = strtotime(date("Ymd", strtotime($date)) . " +1 day"); 

Or, easier:

 date("Ymd H:i:s", time()+((60*60)*24)); 
-3
May 11 '10 at 12:14
source share



All Articles