in reply to time session problem

Something like this perhaps...

use strict; my $start = '12:34:26'; my $end = '14:48:52'; my @start = split(/:/, $start); my @end = split(/:/, $end); $start = 60 * 60 * $start[0] + 60 * $start[1] + $start[2]; $end = 60 * 60 * $end[0] + 60 * $end[1] + $end[2]; my $elapsed = $end - $start; print $elapsed;
--
<http://www.dave.org.uk>

"Perl makes the fun jobs fun
and the boring jobs bearable" - me

Replies are listed 'Best First'.
Re: Re: time session problem
by lelak (Initiate) on Nov 24, 2000 at 08:03 UTC
    i tried your code! thanx for the solution... i tried it and got an answer like elapsed=80640... how do i convert it again to a format of hr:min:sec? thanx! thanx a lot man!

      I already did something like that here

      --
      <http://www.dave.org.uk>

      "Perl makes the fun jobs fun
      and the boring jobs bearable" - me

      sub time_format { my $time = shift; my @parts; if ($time >= 3600) { my $hours = int($time / 3600); $time -= $hours * 3600; push @parts, $hours; } if ($time >= 60) { my $minutes = int($time / 60); $time -= $minutes * 60; push @parts, $minutes; } else { push @parts, 0 if @parts; } push @parts, $time; return sprintf join(':', ('%02d') x @parts), @parts; }