Rick, True...good tip. I generally ignore the timezone and weekday patterns when I parse date strings and didn't think of the ambiguity. I generally pattern match to extract the pieces I want and then pass those to Strptime with any explicit options needed for my particular data source or storage requirements.
Bobby > -----Original Message----- > From: Rick Measham [mailto:ri...@isite.net.au] > Sent: Tuesday, March 17, 2009 6:34 PM > To: jim.mo...@yahoo.com > Cc: datetime@perl.org > Subject: Re: Module To Parse Format 'Friday, March 13, 2009 04:20 PM EST' > > Metz, Bobby wrote: > > Jim, > > You don't need to write your own module to handle these. Just use > the DateTime::Format::Strptime module. Modify the parser example below > with a pattern to suit your own format. $dt will hold your new datetime > object with the values parsed from your string format. > > > > my $parser = DateTime::Format::Strptime->new(pattern => '%a %b %d > %H:%M:%S %Y'); > > my $dt = $parser->parse_datetime($val); > > > > See the CPAN page for all of the pattern options: > > > > http://search.cpan.org/~rickm/DateTime-Format-Strptime- > 1.0900/lib/DateTime/Format/Strptime.pm > > Strptime is the 'easy' answer but isn't quite correct. > > Here's the example again: > Friday, March 13, 2009 04:20 PM EST > > %a = Friday, > %b = March, > %d = 13, > %Y = 2009, > %I = 04, > %M = 20, > %p = pm, > %Z = EST, > > So we have the pattern: "%a, %b %d, %Y %I:%M %p %Z" > > HOWEVER: 'EST' is ambiguous so it won't work. Are you always in the same > time zone? If so, use the pattern "%a, %b %d, %Y %I:%M %p EST" and set > the time zone explicitly. > > Cheers! > Rick Measham > > -- > Message protected for iSite by MailGuard: e-mail anti-virus, anti-spam > and content filtering. > http://www.mailguard.com.au >