简体   繁体   中英

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 stores digits and not words for dates. how do you convert the number 12 into the word december?

尝试此操作,并查看日期函数以获取更多答案:

date('F', mktime(0, 0, 0, 12))

您可以这样做:

echo date('F', mktime(0, 0, 0, 12));
strftime("%B", mktime(0, 0, 0, 12));

就像date()一样,除了如果您事先使用setlocale设置语言环境,它将为您进行本地化。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM