I'm trying to add days to a date in the past.

I know this adds 30 days to today's date:

$newdate = (date('Y-m-d', strtotime('+ 30 days')));

But let's say I have a date variable:

$pastdate = '2006-05-06';

And now I want to add 30 days to that, so it reads: 2006-06-06.

I'm sure it's an easy thing, but I'm not sure where to look in the php manual for this.

Thanks!

    I don't understand the question.

    It is 31 days between 2006-05-06 and 2006-06-06. If you want to add a month I suggest that you do that instead of 30 days.

    Or you may have problems with how to write it. Something like this would probaly work:

    $pastdate = '2006-05-06';
    $newdate = (date($pastdate, strtotime('+ 30 days')));
    

    Oh, by the way. What about look at [man]date[/man] in the manual?

      Actually, the correct syntax would be:

      strtotime($date . ' +30 days')

      Though I agree with Piranha - use +1 month if that's what you're trying to do.

        This is what I was looking for:

        <?php
        
        $date = '2006-05-06'; // some time in the past
        
        $add_a_month= date('Y-m-d', strtotime('+30 days', strtotime($date)));
        
        echo $add_a_month;
        ?> 

        This gives us: 2006-06-05

        I must give NogDog credit for this part, as he sent me some help. But I do apologize for not being clearer with what I was looking for.

        Thanks guys for your input! I'll try to be more specific next time!

          I didn't realize you could combine both an exact date string with a relative date string in the same strtotime(), so you could shorten that to:

          <?php
          
          $date = '2006-05-06'; // some time in the past
          
          $add_a_month= date('Y-m-d', strtotime($date.' +30 days'));
          
          echo $add_a_month;
          ?> 
          
            Write a Reply...