Jump to content

Finding the Name of a Month Based on Number


ShoeLace1291

Recommended Posts

Using an array, and keys.

 

<?php

$month_names = array("","January","February","March","April","May","June","July","August","September","October","November","December");

echo $month_names[$month_number];

?>

Link to comment
Share on other sites

I am trying to convert a number of the month to the name of the month... For example:  12 would convert to December.  What's the best way to do this?

 

Context would be helpful since there's probably more than one "best way".

Link to comment
Share on other sites

Context would be helpful since there's probably more than one "best way".

I agree, there is always more than one way to do things. If you don't feel like writing out the names, you could use:

echo date( 'F', mktime( 0, 0, 0, $month_number ) );

Probably not as efficient, but less typing.

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.