hellouthere Posted March 31, 2007 Share Posted March 31, 2007 i have a date in the format yyyy-mm-dd i need to add 1 month to this date... i can split it into an array... then add 1 to the second value in the array (month) but how can i do this without ending up with 13 months in a year etc... if you see what i mean... at the moment the script treats it as a string of, i need it to treat it as a date... thanks in advance... Link to comment https://forums.phpfreaks.com/topic/45033-solved-help-with-date/ Share on other sites More sharing options...
Heero Posted March 31, 2007 Share Posted March 31, 2007 PHP actually comes with a bunch of functions to modify dates. You shouldn't have to do any splitting into array. You might want to refer to the PHP manual about date. Link to comment https://forums.phpfreaks.com/topic/45033-solved-help-with-date/#findComment-218608 Share on other sites More sharing options...
metrostars Posted March 31, 2007 Share Posted March 31, 2007 date("Y-m-d", mktime(0, 0, 0, date("m") + 1, date("d"), date("Y"))); Link to comment https://forums.phpfreaks.com/topic/45033-solved-help-with-date/#findComment-218610 Share on other sites More sharing options...
Jove Posted March 31, 2007 Share Posted March 31, 2007 look for the function strtotime Link to comment https://forums.phpfreaks.com/topic/45033-solved-help-with-date/#findComment-218613 Share on other sites More sharing options...
hellouthere Posted March 31, 2007 Author Share Posted March 31, 2007 thx all, especially metrostars... i have applied and read into those standard functions... Link to comment https://forums.phpfreaks.com/topic/45033-solved-help-with-date/#findComment-218617 Share on other sites More sharing options...
kenrbnsn Posted March 31, 2007 Share Posted March 31, 2007 I find using the strtotime() function easier to use: <?php $test_date = '2007-12-10'; echo date('Y-m-d',strtotime($test_date . ' +1 month')); ?> Ken Link to comment https://forums.phpfreaks.com/topic/45033-solved-help-with-date/#findComment-218654 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.