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?
-1 - OP is looking for month names
symcbean
2010-05-05 12:56:41
@symcbean: I did not notice that but fixed before seeing your comment. Thanks
Sarfraz
2010-05-05 12:57:10
The code will work fine, so long as the script is only ever executed in January.
salathe
2010-05-05 13:47:27
@Sarfraz: `foreach (range(1,12) as $num) echo date('F', strtotime($num));` gives `JanuaryJanuaryJanuaryJanuaryJanuaryJanuaryJanuaryJanuaryJanuaryJanuaryJanuaryJanuary`
salathe
2010-05-05 14:51:08
@salathe: hmm that's right, unfortunately i only gave try to digit 1, thanks for that, fixed now.
Sarfraz
2010-05-05 14:55:41
@Sarfraz: You're welcome. Aside: why this answer was accepted when it didn't do what was asked, I've no idea!
salathe
2010-05-05 15:35:12
@salath: yup, the answer of St. John Johnson should be accepted still.
Sarfraz
2010-05-05 16:48:09
+10
A:
Try this and look at the date function for more answers:
date('F', mktime(0, 0, 0, 12))
St. John Johnson
2010-05-05 12:54:45
+2
A:
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.
Manos Dilaverakis
2010-05-05 13:01:22
+2
A:
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
Gordon
2010-05-05 13:59:16
Or in PHP-land (as of PHP 5.3) if for some reason doing it in MySQL isn't possible: `DateTime::createFromFormat('n', $num)->format('F')`
salathe
2010-05-05 15:42:38