cunoodle2 Posted March 29, 2010 Share Posted March 29, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/196865-last-month-not-working-correctly/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 29, 2010 Share Posted March 29, 2010 It's because you are supplying a day number date("d") that does not exist in the month being referenced. Use a 1 in the day number position. Quote Link to comment https://forums.phpfreaks.com/topic/196865-last-month-not-working-correctly/#findComment-1033509 Share on other sites More sharing options...
cunoodle2 Posted March 29, 2010 Author Share Posted March 29, 2010 AWESOME! Thank you so much for that. I was pulling my hair out on that one and was ready to give up. Very much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/196865-last-month-not-working-correctly/#findComment-1033554 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.