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 Answers 2

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);
Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, thanks for pointing that out, I actually came back with the idea of editing that. :D
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).

1 Comment

Thanks your answer works! However on reflection I agree the other answer is more simply way of going about doing this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.