L
Leif Wessman
What's the best way to parse a date in a, for me, known format?
In my case the months are spelled a little different (not matching a
specific locale). But I know than "janu" means "january" and that the
format of the date is "date year month".
First of all I need a way to check if the datetext has the format that
I think it should have.
Then I would like to change this datetext into a common format that a
regular date parser would understand.
use strict;
use warnings;
my @months =
("janu","febr","mars","apri","maj","juni","juli","augu","sept","okto","nove","dece");
my $dateformat = "dd yy/@months";
my $datetext = "05 04/janu";
# Now I need to create a regular expression
# to see if $datetext matches $dateformat
my $regexp = ...; # need help here
if ($datetext =~ /$regexp/) {
# Now I need to modify it into a common
# format, like: "05-01-2004"
} else {
print "wrong format";
}
Thanks for any input!
Leif
In my case the months are spelled a little different (not matching a
specific locale). But I know than "janu" means "january" and that the
format of the date is "date year month".
First of all I need a way to check if the datetext has the format that
I think it should have.
Then I would like to change this datetext into a common format that a
regular date parser would understand.
use strict;
use warnings;
my @months =
("janu","febr","mars","apri","maj","juni","juli","augu","sept","okto","nove","dece");
my $dateformat = "dd yy/@months";
my $datetext = "05 04/janu";
# Now I need to create a regular expression
# to see if $datetext matches $dateformat
my $regexp = ...; # need help here
if ($datetext =~ /$regexp/) {
# Now I need to modify it into a common
# format, like: "05-01-2004"
} else {
print "wrong format";
}
Thanks for any input!
Leif