Unix Shell - how to find the time difernce between two given time

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > December 2007 > how to find the time difernce between two given time





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 how to find the time difernce between two given time
vs.vivek1@gmail.com

2007-12-06, 7:36 am

for eg

time interval between 12:17:47 20/11/07 and 17:23:47 21/11/07

like this

please help ; i am doing a project which need this time differnce

Regards;
Vivek
Stephane Chazelas

2007-12-06, 7:36 am

On Thu, 6 Dec 2007 00:16:50 -0800 (PST), vs.vivek1@gmail.com wrote:
> for eg
>
> time interval between 12:17:47 20/11/07 and 17:23:47 21/11/07
>
> like this
>
> please help ; i am doing a project which need this time differnce

[...]

perl (at least, but that probably applies to ruby and Python as
well) has date manipulation modules, so you may consider doing
it in perl.

In shells, there's not much, at least standard.

Recent versions of ksh93 have date manipulation capabilities
built in though it's hardly documented.

See its printf %T

GNU date has a -d option to parse a date.

If you don't care about timezones or DST, you can use the POSIX
shell functions available at
http://stchaz.free.fr/wide_strftime.sh (you'll want to use the
timegm() function).

In the standard toolchest, the only utility that parses a date
as far as I know is touch. Then you can use "pax" to retrieve
the modification time of a file in seconds since the epoch, but
that's a bit convoluted as you need to parse the archive format.

--
Stephane
Grant

2007-12-06, 7:36 am

On Thu, 6 Dec 2007 00:16:50 -0800 (PST), "vs.vivek1@gmail.com" <vs.vivek1@gmail.com> wrote:

>for eg
>
>time interval between 12:17:47 20/11/07 and 17:23:47 21/11/07


~$ gawk 'BEGIN{print mktime("2007 11 21 17 23 47") - mktime("2007 11 20 12 17 47"),"seconds"}'
104760 seconds

Grant.
William James

2007-12-06, 1:29 pm

On Dec 6, 2:16 am, "vs.viv...@gmail.com" <vs.viv...@gmail.com> wrote:
> for eg
>
> time interval between 12:17:47 20/11/07 and 17:23:47 21/11/07
>
> like this
>
> please help ; i am doing a project which need this time differnce
>
> Regards;
> Vivek


ruby -e 'a,b=ARGF.map{|s| Time.local(*s.split(/
\D/).values_at(5,4,3,0,1,2))}
p b-a' time_file

If "time_file" contains
12:17:47 20/11/07
17:23:47 21/11/07
then the output will be
104760.0
William James

2007-12-06, 1:29 pm

On Dec 6, 12:20 pm, William James <w_a_x_...@yahoo.com> wrote:
> On Dec 6, 2:16 am, "vs.viv...@gmail.com" <vs.viv...@gmail.com> wrote:
>
>
>
>
>
>
> ruby -e 'a,b=ARGF.map{|s| Time.local(*s.split(/
> \D/).values_at(5,4,3,0,1,2))}
> p b-a' time_file
>
> If "time_file" contains
> 12:17:47 20/11/07
> 17:23:47 21/11/07
> then the output will be
> 104760.0


Google garbled it.

ruby -e 'a,b=ARGF.map{|s| Time.local(*s.split(/\D/).
values_at(5,4,3,0,1,2))}; p b-a' time_file

If "time_file" contains
12:17:47 20/11/07
17:23:47 21/11/07
then the output will be
104760.0
Cyrus Kriticos

2007-12-06, 7:25 pm

vs.vivek1@gmail.com wrote:
> for eg
>
> time interval between 12:17:47 20/11/07 and 17:23:47 21/11/07
>
> like this


[GNU date & bash]


$ TIME1=$(date -d "2007-11-21 17:23:47" +%s)
$ TIME2=$(date -d "2007-11-20 12:17:47" +%s)
$ let SECS=$TIME1-$TIME2
$ echo $SECS
104760

--
Best regards | Be nice to America or they'll bring democracy to
Cyrus | your country.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2009 webservertalk.com