aslum aslum - 1 year ago 71
PHP Question

convert month from name to number

Is there an easy way to change

$month = "July";
so that
$nmonth = 7
would be fine too).
I could do a case statement, but surely there is already a function to convert?
I wish I could accept multiple answers, cause two of you basically gave me what I needed by your powers combined.

$nmonth = date('m',strtotime($month));

That will give the numerical value for

Answer Source


$date = 'July 25 2010';
echo date('d/m/Y', strtotime($date));

The m formats the month to its numerical representation there.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download