How to convert month number to month name in php
Is there a function in php wherein you can convert the number 12 to its equivalent in a month. For example if the mysql database stor开发者_Go百科es digits and not words for dates. how do you convert the number 12 into the word december?
Try this and look at the date function for more answers:
date('F', mktime(0, 0, 0, 12))
You could do like:
echo date('F', mktime(0, 0, 0, 12));
strftime("%B", mktime(0, 0, 0, 12));
It's like date() except it will take care of localization for you, if you set a locale using setlocale beforehand.
You could also do that directly in MySQL with
SELECT MONTHNAME(STR_TO_DATE(12, '%m')); -- December
See http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_str-to-date
date("F", mktime(0, 0, 0, 12, 1, 2000));
Use this code:
echo date("F", mktime(0, 0, 0, $month, 1, 2010));
Where $month is your number from 1 to 12.
Read more at php functions reference: date
精彩评论