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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.