Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: DIfference in days hours and second between dates

by space_monk (Chaplain)
on Jun 13, 2013 at 15:55 UTC ( #1038780=note: print w/replies, xml ) Need Help??

in reply to DIfference in days hours and second between dates

Please look at the module DateTime or Date::Calc and replace your code with calls to it.

The following is undebugged and untested, so you're welcome to fix any minor issues that show up. :-)

use strict; use warnings; use DateTime; use DateTime::Duration; use DateTime::Format::Strptime; sub timeDiff { # invoke isn't used, what's it for? my $invoke = shift || ''; my $date1 = shift || ''; my $date2 = shift || ''; my $dParser = DateTime::Format::Strptime->new( pattern => '%F %T', locale => 'en', time_zone => 'CET', on_error => 'croak', ); my $dt1 = $dParser->parse_datetime($date1); my $dt2 = $dParser->parse_datetime($date2); my $dur = $dt2 - $dt1; my ($dd, $hh, $mm, $ss) = $dur->in_units('days', 'hours', 'minutes +', 'seconds'); return "$dd J $hh H $mm M $ss Sec"; }
If you spot any bugs in my solutions, it's because I've deliberately left them in as an exercise for the reader! :-)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1038780]
[shmem]: trying to build a RPM for some perl with a bunch of modules. Trying perlbrew, trying alien.
[stevieb]: finally got my 12v solar setup for my Pi/Arduino, with a 12v 7.2Ah battery. Testing how long the Pi will run on the fully charged battery before I hook it up to the solar regulator. I expect between 8 and 18 hours, depending on load.
[shmem]: ...writing a Makefile for that. Edit, test, lather, rinse, repeat.

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2017-03-25 22:23 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (313 votes). Check out past polls.