Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Answer: Fast(er) date parsing

by fundflow (Chaplain)
on Jul 20, 2000 at 02:08 UTC ( #23311=categorized answer: print w/replies, xml ) Need Help??

Q&A > dates and times > Fast(er) date parsing - Answer contributed by fundflow

Thanks guys, maybe i wasn't clear. I want to get the unix timing (since epoch) from the data and was wondering if there is an inverse function to strftime(). I just realized that its not that hard and so here is my solution, following lhoward's suggestion:
use Time::Local; my %months = ( Jan=> 0, Feb=> 1, Mar=> 2, Apr=> 3, May=>4, Jun=> 5, Jul=> 6, Aug=> 7, Sep=> 8, Sep=> 8, Oct=> 9, Nov=> 10, Dec= +> 11); # Parse the date: Fri Jun 30 11:07:39 2000 my ($day, $month, $mday, $time, $year)=split(" ", $d); my ($hour,$min,$sec)=split(":",$time); my $result = timelocal($sec,$min,$hour,$mday,$months{$month},$year);

I'd prefer not having to use any module but this seems reasonable
The reason i need this is to go through some log files and print a summary of the events that happened in the past 24 hours.

Replies are listed 'Best First'.
Re: Answer: Fast(er) date parsing
by I0 (Priest) on Dec 29, 2000 at 17:34 UTC
    If you just want to check if the event was in the last 24 hours without using any module, you could compare
    my @yesterday=localtime time-24*60*60; if( (sprintf"%02d"x6, $yesterday[5]+1900,@yesterday[4,3,2,1,0]) < (sprintf"%02d"x6, $year,$months{$month},$mday,$hour,$min,$sec) )
Log In?

What's my password?
Create A New User
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2017-11-21 21:08 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (312 votes). Check out past polls.