Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Convert apache log date/time to sql

by hallikpapa (Scribe)
on Mar 31, 2009 at 18:42 UTC ( [id://754500]=perlquestion: print w/replies, xml ) Need Help??

hallikpapa has asked for the wisdom of the Perl Monks concerning the following question:

I have an apache log that stores date/time like this (which is also how it looks in my $var; square brackets and all):
[26/Mar/2009:12:12:48 -0500]


I am attempting to use Date::Parse.
http://search.cpan.org/~gbarr/TimeDate-1.16/lib/Date/Parse.pm

But it doesn't seem to support the format I am in. I am horrible and regular expressions and need some help/suggestions at converting the date above.

This is so I can compare dates from a table that stores dates like:
2009-03-27 14:18:40
<edit> Nevermind. I made a mistake. Didn't mean to post this, sorry. Can delete it.

Replies are listed 'Best First'.
Re: Convert apache log date/time to sql
by codeacrobat (Chaplain) on Mar 31, 2009 at 20:28 UTC
    For the curious, this is one way to parse the date.
    TZ=UTC perl -MDate::Manip=UnixDate -e ' $_=q{[2009/Mar/26:12:12:48 -0500]}; s/:/ /; tr/[]//d; print UnixDate($_,"%Y-%m-%d %H:%M:%S");' 2009-03-26 17:12:48

    print+qq(\L@{[ref\&@]}@{['@'x7^'!#2/"!4']});

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://754500]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-19 05:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found