Month String to Numeric?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Month String to Numeric?

Post by spacebiscuit »

Hi guys,

Given a month as a string, is there a simple way to find the numeric representation of said month?

I've used a switch statement but I'm wondring if there is a more elegant way of doing it?

Thanks in advance,

Rob.
User avatar
markusn00b
Forum Contributor
Posts: 298
Joined: Sat Oct 20, 2007 2:16 pm
Location: York, England

Re: Month String to Numeric?

Post by markusn00b »

How about:

Code: Select all

 
echo date("m", strtotime'June'));
 
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Re: Month String to Numeric?

Post by spacebiscuit »

Many thanks - that works perfectly and of course is far more elegant!

You were missing a opening bracket though :wink:

Rob.
User avatar
markusn00b
Forum Contributor
Posts: 298
Joined: Sat Oct 20, 2007 2:16 pm
Location: York, England

Re: Month String to Numeric?

Post by markusn00b »

robburne wrote:Many thanks - that works perfectly and of course is far more elegant!

You were missing a opening bracket though :wink:

Rob.
My bad.

You're welcome :)

Mark.
Post Reply