Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Convert month name to number

by japhy (Canon)
on Jul 11, 2001 at 00:24 UTC ( [id://95459]=note: print w/replies, xml ) Need Help??


in reply to Convert month name to number

You want a hash.
%mon2num = qw( jan 1 feb 2 mar 3 apr 4 may 5 jun 6 jul 7 aug 8 sep 9 oct 10 nov 11 dec 12 ); print $mon2num{ lc substr($month, 0, 3) };
That works for "JANUARY", "Mar", "decemb.", "oct", and many other variants.

Replies are listed 'Best First'.
Re: Answer: Convert month name to number
by RhetTbull (Curate) on Jul 11, 2001 at 00:56 UTC
    Great implementation japhy! A word of warning to the wise that if you plan on using this with POSIX mktime and friends you'll want to subtract 1 from the month number (e.g. January = 0, December = 11).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://95459]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2024-04-18 15:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found