Find A Month From A Given Integer With PHP

If you need to know the month from a given integer (from 1 to 12) then you can use the following snippet. This will return the string "Feb".

date("M", mktime(0, 0, 0, 2));

This can be encapsulated into a function call that will take a number between 1 and 12 and return the corresponding string for that month. This function includes some simple error checking to make sure that the number is valid before trying to work out the date.

function getMonth($month) 
{
  if (!is_numeric($month) && $month  1 && $month > 12) {
    return false;
  }
  return date("M", mktime(0, 0, 0, $month));
}

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
6 + 0 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.