Reputation: 95
I am using this this syntax to increase one day above but when i put this format it still give me wrong date like this. '01/01/1970' But I want format and date like this '25/08/2016'.
$today = '24/08/2016';
$nextday = strftime("%d/%m/%Y", strtotime("$today +1 day"));
so please help me how can i do this.advance thanx.
Upvotes: 4
Views: 22032
Reputation: 1487
You can use strtotime.
$your_date = strtotime("1 day", strtotime("2016-08-24"));
$new_date = date("Y-m-d", $your_date);
Hope it will help you.
Upvotes: 11
Reputation: 570
Please use below code
<?php
$today = '24/08/2016';
$today = explode('/',$today);
$nextday = date('d/m/Y',mktime(0,0,0,$today[1],$today[0]+1,$today[2])));
?>
Upvotes: 1
Reputation: 6006
If you want to use DateTime:
$today = '24/08/2016';
$nextDay = DateTime::createFromFormat('d/m/Y', $today)
->add(new DateInterval('P1D'))
->format('d/m/Y');
Upvotes: 5
Reputation: 1646
See below perfect working code
<?php
echo $startDate = date('Y-m-d H:i:s'); echo "<br/>";
echo $nextDate = date("Y-m-d H:i:s", strtotime("$startDate +1 day"));
?>
Upvotes: 3
Reputation: 417
It's important to note the different interpretation of -
and /
in the date. If you use a -
php will determine it to be DD-MM
, if you use a /
php will determine it to be MM-DD
.
So you need to use -
instead of /
<?php
$today = '24-08-2016';
echo $nextday = date("d-m-Y", strtotime("$today +1 day"));
?>
Upvotes: 3
Reputation: 8618
You should replace the / with -
Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European** d-m-y format is assumed**.
Reference: http://php.net/manual/en/function.strtotime.php
Try this:
$today = '24/08/2016';
$today = str_replace('/', '-', $today);
$today = date('Y-m-d', strtotime($today));
$nextday = date("d/m/Y", strtotime($today. "+1 day")); // Output: 25/08/2016
Upvotes: 1