""Robert"" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I have a log that I am parsing and I can get the login and logout time
> string parsed out. It looks like this:
>
> 13:50:01    # this is the when the user logged in
> 14:14:35    # this is when the user logged out
>
> I need to get how much time that is but I am not sure how to go about it
> since it is a string (that I assume I have to convert to "real" time to do
> the math with).
>
> Robert
>

I would make some demands that the full date get put in the log, otherwise
when a session spans a change of dates your reports are going to be
incomplete.

Otherwise here is how I would get started:

use warnings;
use strict;
use Time::Piece;

my $login  = Time::Piece->strptime('13:50:01', '%T');
my $logout = Time::Piece->strptime('14:14:35', '%T');

# $diff is a Time::Seconds object
my $diff = $logout - $login;

print('Logged in for: ', $diff->seconds, " seconds\n");

Enjoy,

trwww



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to