Unix Shell - Time difference calculation

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > December 2007 > Time difference calculation





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Time difference calculation
varkey

2007-12-30, 7:37 am

Hi,

I have a file which contains a set of time data as follows

16:37:45
15:45:52
13:48:20
00:20:23

i need to find the time difference with the present time.

Can anyone put some !dea ?

Thanks in advance


Ed Morton

2007-12-30, 7:37 am



On 12/30/2007 6:37 AM, varkey wrote:
> Hi,
>
> I have a file which contains a set of time data as follows
>
> 16:37:45
> 15:45:52
> 13:48:20
> 00:20:23
>
> i need to find the time difference with the present time.
>
> Can anyone put some !dea ?


Are those times always in the past and are they always from the current day?

Ed.


Cyrus Kriticos

2007-12-30, 7:37 am

varkey wrote:
> I have a file which contains a set of time data as follows
>
> 16:37:45
> 15:45:52
> 13:48:20
> 00:20:23
>
> i need to find the time difference with the present time.


in seconds? All in the past but today?

$ echo $(( $(date +%s) - $(date -d '13:48:20' +%s) ))
211

--
Best regards
Cyrus
From a jewish slaughterhouse in Iowa (undercover)
http://video.google.com/videoplay?d...687976401601534
Cyrus Kriticos

2007-12-30, 7:37 am

varkey wrote:
> I have a file which contains a set of time data as follows
>
> 16:37:45
> 15:45:52
> 13:48:20
> 00:20:23
>
> i need to find the time difference with the present time.


in seconds? All from today?

[GNU date & bash]

$ echo $(( $(date +%s) - $(date -d '13:48:20' +%s) ))
211

--
Best regards
Cyrus
From a jewish slaughterhouse in Iowa (undercover)
http://video.google.com/videoplay?d...687976401601534
varkey

2007-12-30, 1:26 pm

Yeah i need to take the difference from the current time only.
Icarus Sparry

2007-12-30, 1:26 pm

On Sun, 30 Dec 2007 06:04:17 -0800, varkey wrote:

> Yeah i need to take the difference from the current time only.


The date command from the ast-open package has a '-E' (for elapsed)
option that does what you want.

You can get it under an Open Source license from

http://www.research.att.com/sw/download/

Ed Morton

2007-12-30, 1:26 pm



On 12/30/2007 8:04 AM, varkey wrote:

[please wquote enough context for your post to stand alone, fixed below]

> Hi,
>
> I have a file which contains a set of time data as follows
>
> 16:37:45
> 15:45:52
> 13:48:20
> 00:20:23
>
> i need to find the time difference with the present time.
>
> Can anyone put some !dea ?
>
> Thanks in advance
>
> Yeah i need to take the difference from the current time only.


With GNU awk:

gawk '{gsub(/:/," ");print systime() - mktime(strftime("%Y %m %d ")$0)}' file

Regards,

Ed.

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2009 webservertalk.com