Operating System - HP-UX
1834550 Members
3291 Online
110069 Solutions
New Discussion

Re: Differnetiate Time stamp .....

 
Manikandan R
Valued Contributor

Differnetiate Time stamp .....

Hi,

I want to differentiate(Subtract) time stamp of two files and i want the output in minutes ...
For ex: File 1 --> Mar 19 12:23
File 2 --> Mar 19 11:00

I want output as 83 (mins) ...... It should also take into account the date....
3 REPLIES 3
Steven E. Protter
Exalted Contributor

Re: Differnetiate Time stamp .....

Shalom,

You might find A. Clay Stephenson's date hammer useful in such calculations.

Perl
http://hpux.ws/merijn/caljd-2.2.pl

Shell
http://hpux.ws/merijn/caljd-2.25.sh

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
john korterman
Honored Contributor

Re: Differnetiate Time stamp .....

Hi,

if you do not mind using a lot of system resources (and will not wait for a perl one-liner), try the attached scrpt.
It counts the number of seconds from a certain date back to January 1st 00:00 of a certain year, e.g. 2000:

File 1 --> Mar 19 12:23
$ ./return_seconds.sh 2000 2007 3 19 12 23 00
227535780


File 2 --> Mar 19 11:00
$ ./return_seconds.sh 2000 2007 3 19 11 00 00
227530800
$

Difference in seconds between the two:
$ echo "227535780 - 227530800" | bc
4980
$

....and converted into minutes:
$ echo "4980 / 60" | bc
83
$

regards,
John K.
it would be nice if you always got a second chance
James R. Ferguson
Acclaimed Contributor

Re: Differnetiate Time stamp .....

Hi:

This Perl snippet will output the difference between the 'mtime' of two files in minutes:

# perl -le '$f1=(stat($ARGV[0]))[9];$f2=(stat($ARGV[1]))[9];print (($f2-$f1)/60)' file1 file2

Regards!

...JRF...