Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Answer: Convert month name to number

by japhy (Canon)
on Jul 11, 2001 at 00:24 UTC ( #95459=categorized answer: print w/replies, xml ) Need Help??

Q&A > dates and times > Convert month name to number - Answer contributed by japhy

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?

What's my password?
Create A New User
[Corion]: I think I'm overdesigning things again. I want to export(later, synchronize) data from Google Keep, by scraping the HTML. And I'm thinking of automating this by having a canary note whose text my program knows and from which it can determine the ...
[Corion]: ... surrounding HTML to scrape all the other notes. Maybe I should better look at dumping all the requests that pass between Google and my "browser" instead.
[choroba]: The older one will even perform twice, once at a retirement home, and then at the music school. It's a day off, but will be pretty busy...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2017-12-12 08:55 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (327 votes). Check out past polls.