Jump to content

[SOLVED] MKTIME show months in order but starts with December not January with month =1


jasonc

Recommended Posts

for ($r=1; $r <= 12; $r++) {
echo(":" . date('F', mktime(0, 0, 0, $r, 0, 0)) .":");
}

 

produces

 

 

:December::January::February::March::April::May::June::July::August::September::October::November:

 

when it would seem it should be

 

:January::February::March::April::May::June::July::August::September::October::November::December:

 

in month/number order ?!

 

is there something wrong with this function or is there something wrong with my code ?

There is nothing wrong with using year 0 (it equates to 2000). The problem is using day 0: a month starts with day 1 and 0 means the last day of the previous month. Just change the day parameter from 0 to 1.

Be warned that by missing the $day parameter out, it will assume the current day. When it comes to the end of a month (anything after the 29th) you'll run into trouble since there is no 30th of some months (february will suffer even more). For example, if today was the 31st then the list of months would be :January::March::March::May::May::July::July::August::October::October::December::December:. Best just stick a 1 into the $day parameter.

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.