I have a PHP date in the form 2013-01-22 , and I want to get the date of tomorrowrows in the same format, e.g. 2013-01-23 .
2013-01-22
2013-01-23
How is this possible with PHP?
Use datetime
$datetime = new DateTime('tomorrow'); echo $datetime->format('Ymd H:i:s');
Or:
$datetime = new DateTime('2013-01-22'); $datetime->modify('+1 day'); echo $datetime->format('Ymd H:i:s');
$datetime = new DateTime('2013-01-22'); $datetime->add(new DateInterval("P1D")); echo $datetime->format('Ymd H:i:s');
Or in PHP 5.4+:
echo (new DateTime('2013-01-22'))->add(new DateInterval("P1D")) ->format('Ymd H:i:s');
$tomorrow = date("Ymd", strtotime('tomorrow'));
or
$tomorrow = date("Ymd", strtotime("+1 day"));
Help link: STRTOTIME ()
Since you noted this with strtotime , you can use it with the +1 day modifier as follows:
+1 day
$tomorrow_timestamp = strtotime('+1 day', strtotime('2013-01-22'));
However, it is a much better solution to use DateTime .
<? php //1 Day = 24*60*60 = 86400 echo date("dmY", time()+86400); ?>
/** * get tomorrow date in the format requested, default to Ymd for MySQL (eg 2013-01-04) * * @param string * * @return string */ public static function getTomorrowsDate($format = 'Ym-d') { $date = new DateTime(); $date->add(DateInterval::createFromDateString('tomorrow')); return $date->format($format); }
It may seem strange that it works fine: date_create( '2016-02-01 + 1 day' );
date_create( '2016-02-01 + 1 day' );
echo date_create( $your_date . ' + 1 day' )->format( 'Ymd' );
Gotta do it
here is the working function
function plus_one_day($date){ $date2 = formatDate4db($date); $date1 = str_replace('-', '/', $date2); $tomorrow = date('Ym-d',strtotime($date1 . "+1 days")); return $tomorrow; }
echo date ('Ym-d',strtotime('+1 day', strtotime($your_date)));
Use DateTime :
DateTime
Get tomorrow from now on:
$d = new DateTime('+1day'); $tomorrow = $d->format('d/m/Y his'); echo $tomorrow;
Results: 06/28/2017 08/13/20
To receive tomorrow from the date:
$d = new DateTime('2017/06/10 08.16.35 +1day') $tomorrow = $d->format('d/m/Y his'); echo $tomorrow;
Results: 06/11/2017 08.16.35
Hope this helps!
$date = '2013-01-22'; $time = strtotime($date) + 86400; echo date('Ym-d', $time);
Where 86400 is the number of seconds per day.