// This function returns month name for the month number submitted as its argument. // *** By Amer Murshed*** function getMonthName($month) { switch ($month) { case 1: echo "January"; break; case 2: echo "February"; break; case 3: echo "March"; break; case 4: echo "April"; break; case 5: echo "May"; break; case 6: echo "June"; break; case 7: echo "July"; break; case 8: echo "August"; break; case 9: echo "September"; break; case 10: echo "October"; break; case 11: echo "November"; break; case 12: echo "December"; break; default: echo " Error! The value entered is not a month number please enter number 1-12."; } }
Month Number to Month Name Function
Month Number to Month Name Function
Last edited by jacek on Tue Oct 11, 2011 6:25 pm, edited 1 time in total.
Reason: code tags...
Reason: code tags...
Re: Month Number to Month Name Function
A more efficient (+faster) way:
function getMonthName($month){ $months = array('-', 'January', 'Februrary', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); if(isset($months[$month])) return $months[$month]; else return '-'; }
Re: Month Number to Month Name Function
Or:
Multi language:
Multi language:
function get_month_name($month){ return strftime('%B', mktime(0, 0, 0, $month, 0, 0)); }English
function get_month_name($month){ return date('F', mktime(0, 0, 0, $month, 0, 0)); }
Re: Month Number to Month Name Function
There's SO much you can do with the date function and its relatives!libeco wrote:Or:
...
-
- Posts: 8
- Joined: Mon Jul 18, 2011 10:15 pm
Re: Month Number to Month Name Function
When i pass in 9, i get august... so maybe this will be better...libeco wrote:Or:
Multi language:function get_month_name($month){ return strftime('%B', mktime(0, 0, 0, $month, 0, 0)); }
function get_month_name($month){ $month = $month+1; return strftime('%B', mktime(0, 0, 0, $month, 0, 0)); }