110

I have a PHP date in the form of 2013-01-22 and I want to get tomorrows date in the same format, so for example 2013-01-23.

How is this possible with PHP?

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
Justin
  • 42,716
  • 77
  • 201
  • 296

10 Answers10

231

Use DateTime

$datetime = new DateTime('tomorrow');
echo $datetime->format('Y-m-d H:i:s');

Or:

$datetime = new DateTime('2013-01-22');
$datetime->modify('+1 day');
echo $datetime->format('Y-m-d H:i:s');

Or:

$datetime = new DateTime('2013-01-22');
$datetime->add(new DateInterval("P1D"));
echo $datetime->format('Y-m-d H:i:s');

Or in PHP 5.4+:

echo (new DateTime('2013-01-22'))->add(new DateInterval("P1D"))
                                 ->format('Y-m-d H:i:s');
John Conde
  • 217,595
  • 99
  • 455
  • 496
109
 $tomorrow = date("Y-m-d", strtotime('tomorrow'));

or

  $tomorrow = date("Y-m-d", strtotime("+1 day"));

Help Link: STRTOTIME()

entio
  • 3,816
  • 1
  • 24
  • 39
Laura Chesches
  • 2,493
  • 1
  • 19
  • 15
17

Since you tagged this with , you can use it with the +1 day modifier like so:

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

That said, it's a much better solution to use DateTime.

Community
  • 1
  • 1
Rudi Visser
  • 21,350
  • 5
  • 71
  • 97
15
<? php 

//1 Day = 24*60*60 = 86400

echo date("d-m-Y", time()+86400); 

?>
richard
  • 12,263
  • 23
  • 95
  • 151
andy
  • 217
  • 3
  • 3
8

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

ABDUL JAMAL
  • 452
  • 7
  • 12
5

Use DateTime:

To get tomorrow from now :

$d = new DateTime('+1day');
$tomorrow = $d->format('d/m/Y h.i.s');
echo $tomorrow;

Results : 28/06/2017 08.13.20

To get tomorrow from a date :

$d = new DateTime('2017/06/10 08.16.35 +1day')
$tomorrow = $d->format('d/m/Y h.i.s');
echo $tomorrow;

Results : 11/06/2017 08.16.35

Hope it helps!

Gregorio
  • 197
  • 3
  • 9
1
/**
 * get tomorrow's date in the format requested, default to Y-m-d for MySQL (e.g. 2013-01-04)
 *
 * @param string
 *
 * @return string
 */
public static function getTomorrowsDate($format = 'Y-m-d')
{
    $date = new DateTime();
    $date->add(DateInterval::createFromDateString('tomorrow'));

    return $date->format($format);
}
crmpicco
  • 16,605
  • 26
  • 134
  • 210
1

By strange it can seem it works perfectly fine: date_create( '2016-02-01 + 1 day' );

echo date_create( $your_date . ' + 1 day' )->format( 'Y-m-d' );

Should do it

Markus Safar
  • 6,324
  • 5
  • 28
  • 44
-1

here's working function

function plus_one_day($date){
 $date2 = formatDate4db($date);
 $date1 = str_replace('-', '/', $date2);
 $tomorrow = date('Y-m-d',strtotime($date1 . "+1 days"));
 return $tomorrow; }
-4
$date = '2013-01-22';
$time = strtotime($date) + 86400;
echo date('Y-m-d', $time);

Where 86400 is the # of seconds in a day.

Jason
  • 1,192
  • 7
  • 8