Re: Module To Parse Format 'Friday, March 13, 2009 04:20 PM EST'

[email protected] (Rick Measham)
Newsgroups perl.datetime
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.