Jump to content

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


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.

thanks for that it works now i have taken out all the ending parts of the date that were not needed.

 

just used...  echo(":" . date('F', mktime(0, 0, 0, $r)) .":");

instead

 

thanks for your help

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.

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.