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

could anybody shed me some light on how could i get the session time or should i say the time elapse between 12:34:26 and 14:48:52 and the time format will be 24-hour

Replies are listed 'Best First'.
Re: time session problem
by davorg (Chancellor) on Nov 23, 2000 at 14:09 UTC

    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

      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; }
Re: time session problem
by mitd (Curate) on Nov 23, 2000 at 11:47 UTC
    Go forth and get Date::Calc or you could to more work something like this.
    $start = time(); ... time passes $stop = time(); $stop - $start = $seconds_elapsed; # bunch of seconds in a minute, minutes in an hour code ...
    Update
    Holy Stereo Farts!
    above is wrong lasst assignment should be:
    #seconds_elapsed = $stop - $start;

    thx Albannach

    Look ... other there ---> Date::Calc grab it and save brain cells.

    mitd-Made in the Dark
    'My favourite colour appears to be grey.'

Re: time session problem
by zejames (Hermit) on Nov 23, 2000 at 16:29 UTC
    Example:

    use Date::Calc qw(Delta_DHMS); my $string1 = '12:34:26'; my $string2 = '14:48:52'; my @time1 = split /:/, $string1; my @time2 = split /:/, $string2; my @fakeday = (2000,1,1); # Let's assume you don't want different day +s print join(':', (Delta_DHMS(@fakeday,@time1, @fakeday,@time2))[1..3] ); __END__

    HTH
    James
Re: time session problem
by tune (Curate) on Nov 23, 2000 at 19:00 UTC
    Time::Local module is also a useful thing. You can convert timestamps to UNIX timeformat (yes the big number) with the timelocal() function, and substract timestamp2 from timestamp1.

    -- tune