date("m"); returns the following result for this month... "02"
That is fine and dandy, but the problem is, I need to change 02 into February, and not by changing it to date("F");
I need to use the date function to convert the supplied number of 02 into February, is there a way of going about this logically without a bunch of if/else statements??
While date('F') would be preferred:
$monthnames = array(
'01'=>'January',
'02'=>'February',
'03'=>'March'
); // and so on...
echo $monthnames[date("m")];
EDIT Adjusting to hitherto unspecified requirement:
$ts = mktime (0, 0, 0, date("m"), 1, date("Y"));
<?php
$convertIntegerToMonth = array(
1 => 'January',
2 => 'February',
3 => 'March',
...
);
$number = 2;
echo $convertIntegerToMonth[(int)$number];
?>
Forget those arrays! What about localization?
This will convert "02" to "February"
<?php
$month = date("m"); // "02"
$newstr = date("F", mktime(0, 0, 0, $month)); // "February"
?>
A simple way to do it:
date('F', strtotime("2000-$month-01"))
This code is working properly:
<?php
$year = 2016;
$month = 02;
echo date("M", mktime(null, null, null,$month+1, null, $year));
?>