Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Manipulate Month from string to number

Status
Not open for further replies.

TanyaB

Programmer
Aug 15, 2001
18
IL
Hi all,
Question:

In my script, i get the file's creation month in locale's abbreviated month name format ( as 'date +%b' in unix - Jan, Feb and so on);
what's the easiest way to convert it to month's number?
thanks in advnce.
 
Easiest way's probably just to construct a hash (though there's probably a module that'll do it:
Code:
my %months;

@months{ qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/ } = 1 .. 12;

my $month_name = 'Feb';
my $month_number = $months{ $month_name };
 
Thanks!
Actually, i was trying with all this localtime and timelocals... but this is actually much easier :)
thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top