Solved

Perl Time Stamp Calculation

Posted on 2009-05-05
4
1,321 Views
Last Modified: 2012-05-06
I have a file that contains start and end times for processes:
     Start BatPrcsDrvr.pl CAEXPENS 1    2009-05-05 01:05:52
     End BatPrcsDrvr.pl CAEXPENS 1 Successfully    2009-05-05 01:05:53
     Start BatPrtnDrop.pl CAEXPENS 1    2009-05-05 01:06:12
     End BatPrtnDrop.pl CAEXPENS 1 Successfully    2009-05-05 01:15:29
     Start BatBackup.pl CAEXPENS 1    2009-05-05 01:21:11
     End BatBackup.pl CAEXPENS 1 Successfully    2009-05-05 01:25:57
etc.
I want to take the time stamp on the End line and compare it to the time stamp on the start line to get the elapsed time.  I am working on this now but not getting very far so any tips would be appreciated.  I will repost if I figure it out first.
0
Comment
Question by:Angela_Wilcox
  • 2
4 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 400 total points
Comment Utility
use  Time::Local;
$_='Start BatPrcsDrvr.pl CAEXPENS 1    2009-05-05 01:05:52';
@d=/(\d+)-(\d+)-(\d+)\s+(\d+):(\d+):(\d+)/;
$timestamp = timelocal(@d[5,4,3,2],$d[1]-1,$d[0]);

0
 

Author Comment

by:Angela_Wilcox
Comment Utility
Epoch time conversion  - Exactly what was needed...
0
 
LVL 5

Assisted Solution

by:vikaskhoria
vikaskhoria earned 100 total points
Comment Utility
You can also use the CPAN, Date::Manip modules to manipulate date. This also handles text having dates.

See:
http://search.cpan.org/~sbeck/Date-Manip-5.54/lib/Date/Manip.pod
0
 

Author Comment

by:Angela_Wilcox
Comment Utility
Although the Date:: Manip could probably also do what I needed - I took the first authors comments and created a function then imbedded this into my output as follows - this is in a while loop that does other stuff as well but thought I would show how I used the solution - thanks to both of you for your help.

print $fh_output_time_log ("$_", " ", &epoch_time($_) ," \n");

sub epoch_time
{
    local @_;
    @d=/(\d+)-(\d+)-(\d+)\s+(\d+):(\d+):(\d+)/;
    return(sprintf(timelocal(@d[5,4,3,2],$d[1]-1,$d[0])));
}
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now