Jump to content

strtotime issue


nikko50

Recommended Posts

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);

Link to comment
https://forums.phpfreaks.com/topic/263153-strtotime-issue/
Share on other sites

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 ) 

Link to comment
https://forums.phpfreaks.com/topic/263153-strtotime-issue/#findComment-1348718
Share on other sites

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

 

Link to comment
https://forums.phpfreaks.com/topic/263153-strtotime-issue/#findComment-1348742
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.