[syntax=php]// 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.";
}
}[/syntax]
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:
[syntax=php]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 '-';
}[/syntax]
[syntax=php]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 '-';
}[/syntax]
Re: Month Number to Month Name Function
Or:
Multi language:
[syntax=php]function get_month_name($month){
return strftime('%B', mktime(0, 0, 0, $month, 0, 0));
}[/syntax]
English
[syntax=php]function get_month_name($month){
return date('F', mktime(0, 0, 0, $month, 0, 0));
}[/syntax]
Multi language:
[syntax=php]function get_month_name($month){
return strftime('%B', mktime(0, 0, 0, $month, 0, 0));
}[/syntax]
English
[syntax=php]function get_month_name($month){
return date('F', mktime(0, 0, 0, $month, 0, 0));
}[/syntax]
Re: Month Number to Month Name Function
libeco wrote:Or:
...
There's SO much you can do with the date function and its relatives!
-
- Posts: 8
- Joined: Mon Jul 18, 2011 10:15 pm
Re: Month Number to Month Name Function
libeco wrote:Or:
Multi language:
[syntax=php]function get_month_name($month){
return strftime('%B', mktime(0, 0, 0, $month, 0, 0));
}[/syntax]
When i pass in 9, i get august... so maybe this will be better...
[syntax=php]function get_month_name($month){
$month = $month+1;
return strftime('%B', mktime(0, 0, 0, $month, 0, 0));
}[/syntax]