mouli Posted August 19, 2007 Share Posted August 19, 2007 Hi I am using a very simple date function to add a number of days to a starting date. Sounds so simple and it is but this function works for any date except 4th november 2007.. The function and a sample useage is as follows: function addDays ($days, $fmt="Y-m-d", $date=NULL) { // Adds days to date or from now // By JM, www.Timehole.com if ($date==NULL) { $t1 = time(); } else{$t1 = strtotime($date); $t2 = $days * 86400; // make days to seconds return date($fmt,($t2+$t1));} } $newdate = addDays(1,'Y-m-d','2007-11-5'); echo $newdate; and it works great for any date use but try adding one day to 2007-11-04 and i get 2007-11-04! Its the only date that I can find that doesn't work and I cant figure out why. I'm sure its a simple answer but its got me very puzzled. Have a go and tell me what you get. Many thanks Quote Link to comment https://forums.phpfreaks.com/topic/65680-odd-date-function-behaviour-on-4th-nov-2007/ Share on other sites More sharing options...
Wuhtzu Posted August 19, 2007 Share Posted August 19, 2007 I get the correct date - 2007-11-5 Quote Link to comment https://forums.phpfreaks.com/topic/65680-odd-date-function-behaviour-on-4th-nov-2007/#findComment-328037 Share on other sites More sharing options...
Barand Posted August 19, 2007 Share Posted August 19, 2007 Me too. try <?php function addDays ($days, $fmt="Y-m-d", $date=NULL) { return date($fmt,strtotime("$date +$days days")); } $newdate = addDays(1,'Y-m-d', '2007-11-04'); echo $newdate; ?> Quote Link to comment https://forums.phpfreaks.com/topic/65680-odd-date-function-behaviour-on-4th-nov-2007/#findComment-328045 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.