kony Posted May 1, 2007 Share Posted May 1, 2007 i am trying to make a date function, which well take current date and number of days to be added and well calculate the new date. But i have problem that wheni add, say example current date = 25 / 03/ 2007 + 7 days, it well give me 32 / 04 / 2007. and expected answer is 1 /05 /2007. is there any function in php that well do this job for me. or i 'll have to write the code to check the case of each month?? Link to comment https://forums.phpfreaks.com/topic/49469-add-date-function/ Share on other sites More sharing options...
trq Posted May 1, 2007 Share Posted May 1, 2007 is there any function in php that well do this job for me. Look at the examples in the man page for date. Link to comment https://forums.phpfreaks.com/topic/49469-add-date-function/#findComment-242454 Share on other sites More sharing options...
kenrbnsn Posted May 1, 2007 Share Posted May 1, 2007 Since all of PHP date based functions assume that the date is in the form mm/dd/yyyy (or yy) or yyyy-mm-dd, you would first have to convert your date to one of those forms before using them. <?php $in = '25/03/2007'; list($month,$day,$year) = explode('/',$in); $out = date('d/m/Y',strtotime($month . '/' . $day . '/' . $year . ' +7 days')); echo $out; ?> Ken Link to comment https://forums.phpfreaks.com/topic/49469-add-date-function/#findComment-242538 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.