I have this PHP code:
$monthNum = sprintf("%02s", $result["month"]);
$monthName = date("F", strtotime($monthNum));
echo $monthName;
But it's returning December
rather than August
.
$result["month"]
is equal to 8, so the sprintf
function is adding a 0
to make it 08
.
use the above code
I think using cal_info() is the easiest way to convert from number to string.
See the docs for cal_info()
I know this question was asked a while ago now, but I figured everyone looking for this answer was probably just trying to avoid writing out the whole if/else statements, so I wrote it out for you so you can copy/paste. The only caveat with this function is that it goes on the actual number of the month, not a 0-indexed number, so January = 1, not 0.
Use
mktime()
:See the PHP manual : http://php.net/mktime
You can just use monthname() function in SQL.
SELECT monthname(date_column) from table group by monthname(date_column)
this is trivially easy, why are so many people making such bad suggestions? @Bora was the closest, but this is the most robust
this is the way to do it