I'm using now() in MySQL query.
INSERT INTO table SET data = '$data', date = now()
But I want to add 1 day to this date (so that date should contain tomorrow).
Is it possible?
I'm using now() in MySQL query.
INSERT INTO table SET data = '$data', date = now()
But I want to add 1 day to this date (so that date should contain tomorrow).
Is it possible?
Do you want to add time to a date value? MySQL interval values are used for date and time calculations. There are multiple ways to create an interval value.
One way is to use the following expression in your queries:
date [ + or - ] INTERVAL value [ UNIT ]
| MICROSECOND | SECOND | MINUTE |
| HOUR | DAY | WEEK |
| MONTH | QUARTER | YEAR |
See the full list here.
Date arithmetic is less straightforward than time arithmetic due to the varying length of months and years, so MySQL provides special functions. Alternatively, you could use the DATE_ADD() or DATE_SUB() functions that adds or subtracts a time/date interval to a date value and then returns the result.
-- Results were same for all , '2018-05-02'
DATE_ADD('2018-05-01',INTERVAL 1 DAY);
'2018-05-01' + INTERVAL 1 DAY
'2018-05-01' + INTERVAL 24 HOUR
SELECT DATE_ADD('2100-12-31 23:59:59',INTERVAL '1:1' MINUTE_SECOND);-- '2101-01-01 00:01:00'
SELECT DATE_SUB('1998-01-02', INTERVAL 31 DAY);-- '1997-12-02'
INSERT INTO `table` ( `title` , `date` )
VALUES('tomorrow never dies',NOW()+INTERVAL 1 DAY); --insert tomorrow date
SELECT DATE_ADD( NOW(), INTERVAL 1 DAY);--tomorrow date
SELECT NOW() + INTERVAL 1 DAY;--tomorrow date