spinner0205 Posted October 13, 2011 Share Posted October 13, 2011 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 More sharing options...
codefossa Posted October 13, 2011 Share Posted October 13, 2011 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 https://forums.phpfreaks.com/topic/249070-add-one-month-to-existing-time/#findComment-1279140 Share on other sites More sharing options...
PFMaBiSmAd Posted October 13, 2011 Share Posted October 13, 2011 $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 https://forums.phpfreaks.com/topic/249070-add-one-month-to-existing-time/#findComment-1279147 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.