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

I would like to determine the time elapsed since a set time of format hhmmss (e.g., 082802). I have seen tv_interval, but I'm not sure if it would work with a preset time of my format as a n argument. Any pointers would be appreciated!

Replies are listed 'Best First'.
Re: time elapsed from set time
by kcott (Archbishop) on Sep 11, 2013 at 01:58 UTC

    G'day sjwnih111,

    Welcome to the monastery.

    If you're just looking for a difference between that time today and the current time today, you can use the builtin module, Time::Piece, like this:

    $ perl -Mstrict -Mwarnings -le ' use Time::Piece; my $now = gmtime; my $now_Ymd_date = sprintf "%4s%02s%02s", $now->year, $now->mon, $ +now->mday; my $then_HMS_time = "082802"; my $then_date_time = $now_Ymd_date . $then_HMS_time; my $then = Time::Piece->strptime($then_date_time, "%Y%m%d%H%M%S"); print "Then: ", $then->strftime("%Y-%m-%d %H:%M:%S"); print "Now: ", $now->strftime("%Y-%m-%d %H:%M:%S"); print "Now - Then: ", $now - $then, " seconds"; ' Then: 2013-09-11 08:28:02 Now: 2013-09-11 01:44:18 Now - Then: -24224 seconds

    Note that gives a negative time difference because it's not elapsed time at all, it's ~7 hours in the future. To get an elapsed time, you'll need to provide a date and time in the past to compare with the current date and time. This is what hippo was referring to.

    Of course, if you're piloting a time machine, negative elapsed times might be entirely appropriate. :-)

    -- Ken

      Thanks so much for your help!!!
Re: time elapsed from set time
by hippo (Archbishop) on Sep 10, 2013 at 16:15 UTC

    If you just specify the time in that format, how will you know how many days have elapsed?

Re: time elapsed from set time
by keszler (Priest) on Sep 10, 2013 at 16:04 UTC