Jump to content

Add one month to existing time


spinner0205

Recommended Posts

Okay so I have a time in the format yyyy-mm-dd that is pulled from a MySQL array row and I need to add one month to it then echo that out. I assume it has something to do with the strtotime() and date() functions but I have tried every combination and cannot figure it out. Can I get some assistance please and thank you? Very very very new to php.

 

Here is what I have lol;

$row=mysql_fetch_array($result);
$ddaterow=$row['donation_date'];

 

Like I said the date will always be in the format yyyy-mm-dd

Link to comment
Share on other sites

function getTime($now, $length)
{
    $date = explode('-', $now);
    
    $then = strtotime($length, mktime(0, 0, 0, $date[1], $date[2], $date[0]));
    
    return date('Y-m-d', $then);
}

echo getTime('1992-04-19', '1 month');

 

Outputs

 

1992-05-19

Link to comment
Share on other sites

$new_date = date('Y-m-d',strtotime($row['donation_date'] . '+ 1 month'));

 

Or you can do this simply (and much faster) directly in your query -

 

SELECT donation_date + INTERVAL 1 MONTH as new_date .....

 

You would reference the value as $row['new_date']

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.