how to find the time difernce between two given time

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
vs.vivek1 [ Do, 06 Dezember 2007 09:16 ] [ ID #1886759 ]

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

On Thu, 6 Dec 2007 00:16:50 -0800 (PST), vs.vivek1 [at] 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
Stephane CHAZELAS [ Do, 06 Dezember 2007 09:51 ] [ ID #1886761 ]

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

On Thu, 6 Dec 2007 00:16:50 -0800 (PST), "vs.vivek1 [at] gmail.com" <vs.vivek1 [at] 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.
G_r_a_n_t_ [ Do, 06 Dezember 2007 11:20 ] [ ID #1886764 ]

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

On Dec 6, 2:16 am, "vs.viv... [at] gmail.com" <vs.viv... [at] 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 [ Do, 06 Dezember 2007 19:20 ] [ ID #1886781 ]

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

On Dec 6, 12:20 pm, William James <w_a_x_... [at] yahoo.com> wrote:
> On Dec 6, 2:16 am, "vs.viv... [at] gmail.com" <vs.viv... [at] 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
William James [ Do, 06 Dezember 2007 19:23 ] [ ID #1886782 ]

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

vs.vivek1 [at] 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.
Cyrus Kriticos [ Do, 06 Dezember 2007 20:32 ] [ ID #1886790 ]
Linux » comp.unix.shell » how to find the time difernce between two given time

Vorheriges Thema: Should I be able to scp between two remote hosts?
Nächstes Thema: A ksh problem about pgrep