Php get date from date

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 .

How is this possible with PHP?

+49
date php datetime strtotime
Jan 22 '13 at 14:10
source share
10 answers

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'); 

Or:

 $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'); 
+130
Jan 22 '13 at 14:12
source share
  $tomorrow = date("Ymd", strtotime('tomorrow')); 

or

  $tomorrow = date("Ymd", strtotime("+1 day")); 

Help link: STRTOTIME ()

+31
Dec 15 '15 at 9:47
source share

Since you noted this with strtotime , you can use it with the +1 day modifier as follows:

 $tomorrow_timestamp = strtotime('+1 day', strtotime('2013-01-22')); 

However, it is a much better solution to use DateTime .

+12
Jan 22 '13 at 14:14
source share
 <? php //1 Day = 24*60*60 = 86400 echo date("dmY", time()+86400); ?> 
+12
Oct 24 '13 at 10:35 on
source share
 /** * 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); } 
+1
Jun 09 '15 at 16:26
source share

It may seem strange that it works fine: date_create( '2016-02-01 + 1 day' );

echo date_create( $your_date . ' + 1 day' )->format( 'Ymd' );

Gotta do it

0
Feb 02 '16 at 12:51
source share

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; } 
0
Jan 31 '17 at 8:53 on
source share

echo date ('Ym-d',strtotime('+1 day', strtotime($your_date)));

0
Jun 22 '17 at 5:12
source share

Use 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!

0
Jun 27 '17 at 1:18
source share
 $date = '2013-01-22'; $time = strtotime($date) + 86400; echo date('Ym-d', $time); 

Where 86400 is the number of seconds per day.

-four
Jan 22 '13 at 14:14
source share



All Articles