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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date/time calculations 1

Status
Not open for further replies.

fidge

Technical User
Jun 11, 2003
20
0
0
GB
Hi,

I need to calulate how long a 'transaction' took to complete. I have the start and end times in format yymmddhhmmssss for example;

Start,end
06111500010000,06111500010000
06111500004300,06111500010000

The problem I have is that I can find no way of converting this so that it takes the turnover onto a new minute into the calulation.

Can anynody help point me in the right direction?

Thanks in advance
 
Perhaps you can do something via Perl.
I have used this snippet of code to figure out various time based events:

Code:
#!/bin/perl
#
# Get and display current time
#
$curtime=time();
$curdate=localtime($curtime);
print "\ntoday in seconds = $curtime\n";
print "today = $curdate\n\n";

Simply run that before the transaction starts and save that value. Run it again after the transaction ends, save that value.

Subtract the first value from the second and the result is how long it took in seconds. If the transaction runs longer than 60 seconds - just take the resulting number and divide by 60.

IE if the transaction took 420 seconds to run: 420/60 = 7 minutes.
 
Thanks sbrews.

Unfortunatley the transactionstimes are from a log file, so its an historical check

I was thinking of trying to convert the strings to an epoch value, and subtracting the end from the start. Does that sound a good way? I'm using hpux 11, is there an easy(1) to get the epoch time, and convert my date/time strings to a epoch value?

Cheers.
 
Hi

I just played abit. Works only with [tt]gawk[/tt].
Code:
awk -F, 'NR>1{print mktime("20"gensub(/(..)/,"\\1 ","g",$2))-mktime("20"gensub(/(..)/,"\\1 ","g",$1))}' /input/file

Feherke.
 
Thanks feherke thats worked, although i've had to copy the files into a server with gawk.

I made one slight change and that was to print $0 before it prints out the results.

Thanks again.
 
Here's a snipet that I always use to get time difference regardless of programming languages.

1. Parse hours, minutes, seconds and convert them into micro-seconds where hours is multiplied by 3600000000, minutes is multiplied by 60000000 and seconds is multiplied by 1000000. Add all the micro-seconds and this is total micro-seconds of your first variable.
2. Do the same with your second variable and get the difference(in micro-seconds) between your first and second variable.
3. To get the difference in HH:MM:SS format, you have to reverse the process by :

Divide total-micro-seconds by 3600000000 to give you hours.
Divide the remainder by 60000000 to give the minutes.
divide the remainder by 1000000 to give the seconds.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top