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
https://forums.phpfreaks.com/topic/196865-last-month-not-working-correctly/
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.