Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nosajhpled/e2d61194960193db45aa6ef596ccf980 to your computer and use it in GitHub Desktop.
Save nosajhpled/e2d61194960193db45aa6ef596ccf980 to your computer and use it in GitHub Desktop.
PHP : Return the Name of the Month by Numerical Value
This function will return the name of the month by passing the month's number. (Ex: 1 will return January).
///Return the name of the month /// $month : the number of the month (1 - Jan) // $long (bool) : true for long name; false for short name /* Example : NumToMonth(1,true) will return January NumToMonth(1,false) will return Jan */ function NumToMonth($month,$long) { $rtn =""; $month_names = array(1 => "Jan", 2 => "Feb", 3 => "Mar", 4 => "Apr", 5 => "May", 6 => "Jun", 7 => "Jul", 8 => "Aug", 9 => "Sep", 10 => "Oct", 11 => "Nov", 12 => "Dec", 13 => "January", 14 => "February", 15 => "March", 16 => "April", 17 => "May", 18 => "June", 19 => "July", 20 => "August", 21 => "September", 22 => "October", 23 => "November", 24 => "December"); if ($month >= 1 and $month <= 24) { // multiply $month by 1 to always have a number // 03 will become 3 $rtn = $long ? $month_names[$month + 12] : $month_names[$month*1]; } return $rtn; }
#PHP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment