7th June 2010 - 2 minutes read time
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));
}