Question

I'm getting the output of:

Warning: strtotime() expects parameter 2 to be long, string given in C:\xampp\htdocs\MindWeather\Assimilation\foreca_hourly.php on line 17


Today is 2014117, Tomorrow is 1970101

My code is:

$TodayIs = date('Ynd');
$nextdate = date('Ynd', strtotime($TodayIs,'+ 1 day'));
echo "<br><br> Today is $TodayIs, Tomorrow is $nextdate<br><br>";

I really don't expect to get a 1970-answer. It's supposed to display "Today is 2014117, Tomorrow is 2014118" instead of "Today is 2014117, Tomorrow is 1970101"

Était-ce utile?

La solution

The second parameter to strtotime defaults to current time. So the following should produce desired result:

$nextdate = date('Ynd', strtotime('+1 day'));
// Today is 2014117, Tomorrow is 2014118

Autres conseils

Why don't you make use of a DateTime Class ?

<?php
$date = new DateTime();
echo "Today is ".$date->format('Y/m/d');
$date->add(new DateInterval('P1D'));
echo "<br>Tomorrow is ".$date->format('Y/m/d');

OUTPUT :

Today is 2014/01/17
Tomorrow is 2014/01/18

Try like this:

$TodayIs = date('Ynd');
$nextdate = date('Ynd', strtotime('+ 1 day'));
echo "<br><br> Today is $TodayIs, Tomorrow is $nextdate<br><br>";

PHPfiddle link: http://phpfiddle.org/lite/code/bnf-scw

Try this:

$date = '2013-10-15';

$new_time = strtotime('+1 day', strtotime($date));

echo date('d-m-Y', $new_time); //displays 2013-10-16
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top