Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

parsing date string

by adonai (Initiate)
on Apr 27, 2001 at 22:43 UTC ( #76218=perlquestion: print w/replies, xml ) Need Help??
adonai has asked for the wisdom of the Perl Monks concerning the following question:

Newbie question here;

I have two date strings in the form of

%y%m%d%H%M%S i.e.

What id like to do is calculate the time difference, whats the best method for doing this?

Ive been playing with Date::Manip but cant seem to get the string parsed properly.

Replies are listed 'Best First'.
Re: parsing date string
by OeufMayo (Curate) on Apr 27, 2001 at 23:14 UTC

    Though Date::Manip is certainly able to do this kind of operations, I would not recommand using it. In fact neither the author of this module:
    Is Date::Manip the one you should be using? In my opinion, the answer is no about 90% of the time. This sounds odd coming from the author of the software, but read on.
    Date::Manip is written entirely in perl. It's the most powerful of the date modules. It's also the biggest and slowest.

    There are plenty of specialized module in the Date::* hierarchy that can fill the bill. For instance, I would use Time::Local for this kind of job, but I'm sure one could find a better suited module (maybe Date::Format?). Anyway here's a stab at it:

    use Time::Local; my $time1 = '010101112245'; my $time2 = '010101114556'; foreach ($time1, $time2){ my @t = $time1 =~ /(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/; @t = reverse @t; $_ = timelocal(@t); } print "Difference is: ", ($time1 -$time2), "\n";

    Disclaimer: Code barely tested, not to be used to operate nuclear reactors.

    my $OeufMayo = new PerlMonger::Paris({http => ''});</kbd>
Re: parsing date string
by suaveant (Parson) on Apr 27, 2001 at 23:01 UTC
    convert them into their separate pieces then look at perlman:Time::Local to get their time in seconds... then subtract... or look at Date::Calc, if you need more than just difference in seconds...
                    - Ant
Re: parsing date string
by little (Curate) on Apr 27, 2001 at 22:58 UTC
    You might use POSIX timefmt() and you get easy to maintain numbers, but simply take the two number you have and calculate the diff then use the timefmt() and you get the difference in a nice format, but don't forget to read the man for posix timefmt() :-))
    Have a nice day
    All decision is left to your taste
    whoops, seems I've mixed it up.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://76218]
Approved by root
and the daffodils sway...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2018-04-21 20:14 GMT
Find Nodes?
    Voting Booth?