Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calculate time

Status
Not open for further replies.

Yarka

Technical User
Jan 14, 2007
192
ES
hi,
I've a file as:
....
12 BC CA x xl 23:00:01,234 LAM
18 CA BC xa axj 23:30:12,333 KIL
4 VD GF ll pp 1:06:15,325 LOPP
.....

I need to obtain for each LAM of my file, the time passed between for LAM and 2 lines down. In this exemple, I want to have the time calculated with operation 1:06:15,325 - 23:00:01,234.
Can anybody help me??

Thanks.
 
you'll need to add 24 (1 day) to the hours component if the finish time is less than the start time, and then use convert to seconds and subtract one from the other, and then covert back to hours, or whatever format you need
Code:
function get_secs {
  ($seed)=@_;
($time, $milliseconds)=split (/,/, $seed);
($hours, $mins, $secs) = split (/\:/, $time);
$secs+= ($mins*60) + ($hours*3600);
return $secs;
}
$secs1=get_secs( $time1 );
$secs2=get_secs( $time2 );
if ( $secs2 < $secs1 ) {
   $secs2+=86400; #24 hours
}
$time_diff=$secs2 - $secs1;
Not tested, but should get you started

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top