How do I add 1 day to a date?
I am not a programmer, but I work on one site as an administrator. It was necessary to add 1 day to the date. It seems to me that this should be done here:
$date=substr($order->date,0,10);
Can you tell me how to prescribe all this?
Date format - datetime 2016-09-02 10:13:54
Thanks!
0
Author: Nikita Rogatnev, 2018-12-26
3 answers
Select the appropriate option:
1.
$timestamp = time(); // 1545818743
$datePlus = (new DateTime('@' . $timestamp))
->modify('1 day')
->format(DateTime::ATOM);
var_dump($datePlus);
2.
$dateString = (new DateTime()) -> format(DateTime::ATOM); // 2018-12-26T02:06:57-08:00
$datePlus = (new DateTime($dateString))
->modify('1 day')
->format(DateTime::ATOM);
var_dump($datePlus);
3.
$dateObject = new DateTime(); // object DateTime
$datePlus = $dateObject
->modify('1 day')
->format(DateTime::ATOM);
var_dump($datePlus);
1
Author: eustatos, 2018-12-26 10:29:03
I would do so
$date = date('Y-m-d', strtotime($order->date) + 86400);
If in general, you can also make strtotime "translate the clock", then I just added 86400 seconds (one day) to the date.
$date = date(
'Y-m-d',
strtotime('+1 day', strtotime($order->date))
);
Here you can already write +5 weeks
and anything else instead of +1 day
0
Author: mr. Pavlikov, 2018-12-26 14:59:34
Earned this option:
$date = substr(date('Y-m-d H:i:s', strtotime($order->date.'1 day')),0,10);
-1
Author: kopetan, 2018-12-26 12:09:30