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
https://forums.phpfreaks.com/topic/249070-add-one-month-to-existing-time/
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

$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']

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.