1

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.

2 Answers2

2

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);
Glavić
  • 42,781
  • 13
  • 77
  • 107
brgs
  • 774
  • 2
  • 7
  • 18
  • Yeah, thanks for pointing that out, I actually came back with the idea of editing that. :D – brgs Jan 26 '14 at 08:47
0

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).

mombul
  • 327
  • 1
  • 10
  • Thanks your answer works! However on reflection I agree the other answer is more simply way of going about doing this. – user3236271 Jan 25 '14 at 22:14