Jump to content

Last month not working correctly??


cunoodle2

Recommended Posts

I'm trying to get a list of this month and the previous 6 months (so 7 months today).  This was working fine.. no code changed and all the sudden stopped working.  Here is my code..

<?php


for($i=0;$i<=6;$i++) 
{
        $month = date("Y-M",mktime(0,0,0,date("m")-$i,date("d"),date("Y")));
        list($y,$m) = split("-",$month);
       echo="<option value='$month'>$y $m</option>";
}
?>

 

For no reason that can I determine that list gives me...

2010 Mar
2010 Mar
2010 Jan
2009 Dec
2009 Nov
2009 Oct
2009 Sep

 

Note that "2010 Mar" showing up twice for me in that list. 

 

When I view the html source I get..

<option value='2010-Mar'>2010 Mar</option>
<option value='2010-Mar'>2010 Mar</option>
<option value='2010-Jan'>2010 Jan</option>

 

Any ideas on this one??  I'm guessing that it has something to do with Feb only being 28 days and today is the 29th of Mar.  This looks to be a php bug but I could be wrong.  If anyone has different code I could use that would be appreciated.  Looking for the "YYYY MMM" format.

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.