nikko50 Posted May 26, 2012 Share Posted May 26, 2012 Why is it when I run the below code "Oct 11" is not in my array, but if I change the $endDate to "2012-10-30" it then will show up? What's up with that?? How can I fix this? Tracy $startDate = "2011-08-25"; $endDate = "2012-10-20"; $monthArray = array(); $i = 0; $sd = strtotime($startDate); $ed = strtotime($endDate); while ($sd < $ed) { $monthArray[$i] = date("M y", $sd); $sd = strtotime("+1 month", $sd); $i++; } print_r($monthArray); Quote Link to comment https://forums.phpfreaks.com/topic/263153-strtotime-issue/ Share on other sites More sharing options...
Pikachu2000 Posted May 26, 2012 Share Posted May 26, 2012 Works as written for me. Output is: Array ( [0] => Aug 11 [1] => Sep 11 [2] => Oct 11 [3] => Nov 11 [4] => Dec 11 [5] => Jan 12 [6] => Feb 12 [7] => Mar 12 [8] => Apr 12 [9] => May 12 [10] => Jun 12 [11] => Jul 12 [12] => Aug 12 [13] => Sep 12 ) Quote Link to comment https://forums.phpfreaks.com/topic/263153-strtotime-issue/#findComment-1348718 Share on other sites More sharing options...
Barand Posted May 26, 2012 Share Posted May 26, 2012 If you start on the 30th of a month and add1 month each time Array ( [0] => Aug 11 [1] => Sep 11 [2] => Oct 11 [3] => Nov 11 [4] => Dec 11 [5] => Jan 12 [6] => Mar 12 [7] => Apr 12 [8] => May 12 [9] => Jun 12 [10] => Jul 12 [11] => Aug 12 [12] => Sep 12 [13] => Oct 12 ) Note Feb is missing as Feb 30 is taken to be Mar 2 echo date ('d M Y', strtotime('2011-01-30 + 1 month')); //--> 02 Mar 2011 Quote Link to comment https://forums.phpfreaks.com/topic/263153-strtotime-issue/#findComment-1348742 Share on other sites More sharing options...
silkfire Posted May 26, 2012 Share Posted May 26, 2012 A little tip from me: Always start the date from 1, because that day is guaranteed to exist in any month any year. January 31 + 1 month is 2 March, so it will skip February. Quote Link to comment https://forums.phpfreaks.com/topic/263153-strtotime-issue/#findComment-1348744 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.