how to find the time difernce between two given time

how to find the time difernce between two given time

am 06.12.2007 09:16:50 von vs.vivek1

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

Re: how to find the time difernce between two given time

am 06.12.2007 09:51:22 von Stephane CHAZELAS

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

Re: how to find the time difernce between two given time

am 06.12.2007 11:20:21 von G_r_a_n_t_

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

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

Grant.

Re: how to find the time difernce between two given time

am 06.12.2007 19:20:03 von William James

On Dec 6, 2:16 am, "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

Re: how to find the time difernce between two given time

am 06.12.2007 19:23:36 von William James

On Dec 6, 12:20 pm, William James wrote:
> On Dec 6, 2:16 am, "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

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

Re: how to find the time difernce between two given time

am 06.12.2007 20:32:13 von Cyrus Kriticos

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.