flaab Posted March 14, 2007 Share Posted March 14, 2007 Hi 2 all =) I've to build a function that tells me the resultant date from adding a number of days to a date. Example: function adddate(date, days) { return date + days; } For example if I call with this...adddate(2007-05-05, 5) it should give back a 2007-05-10. I've tried but is hard! It should work with any number of days... Thx. =) Quote Link to comment https://forums.phpfreaks.com/topic/42700-mysql-calculate-difference-between-dates/ Share on other sites More sharing options...
per1os Posted March 14, 2007 Share Posted March 14, 2007 function adddate($date, $days) { list($year, $month, $day) = split("-", $date); //http://us2.php.net/manual/en/function.mktime.php //mktime ( [int $hour [, int $minute [, int $second [, int $month [, int $day [, int $year [, int $is_dst]]]]]]] ) $time = (mktime(0,0,0,$month, $day, $year) + (60*60*24) * $days); return date("Y-m-d", $time); } --FrosT Quote Link to comment https://forums.phpfreaks.com/topic/42700-mysql-calculate-difference-between-dates/#findComment-207179 Share on other sites More sharing options...
kenrbnsn Posted March 14, 2007 Share Posted March 14, 2007 This is fairly simple. Try this: <?php function adddate($dt,$days) { return(date('Y-m-d',strtotime($dt . ' +' . $days . ' days'))); } echo adddate('2007-05-05', 5); ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/42700-mysql-calculate-difference-between-dates/#findComment-207180 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.