Reputation: 25
I am trying to add $input
to my $output
mktime string but it just returns the date today not the date +2 days (eg 2 days ahead) as desired. Can anyone help my with this please?
$input = '+2';
$output = date('j',mktime(0,0,0,date('j'), date('d'), $input ,date('Y')));
I have also tried
$input = +2;
$output = date('j',mktime(0,0,0,date('j'), date('d'), $input ,date('Y')));
but that did not work either.
Any help would be much appreciated, thanks in advance.
Upvotes: 1
Views: 325
Reputation: 806
You can do:
date('j', mktime(0, 0, 0, date('m'), date('d') + 2, date('Y')));
But the easier way would probably be (and more readable one):
$date = strtotime('+2 days');
$output = date('j', $date);
Upvotes: 2
Reputation: 327
The coma before $input is messing with you. You should replace it with a + sign and only have the number of days in your $input. Like this:
$input = 2;
$output = date('j',mktime(0,0,0,date('j'), date('d') + $input,date('Y')));
But there are better ways to do this (see other answers).
Upvotes: 0