Layric Layric - 6 months ago 10
PHP Question

date("m"); returns the following result for this month... "02"

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??

Answer

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"));

doc: http://us2.php.net/manual/en/function.mktime.php