Calculating deltas between date & time stamps

Calculating deltas between date & time stamps

Post by Jim O'Sh » Sat, 01 Mar 1997 04:00:00



I'm writing a script that requires me to calculate the difference in
seconds between two time and dates stamps.  An example of this is:

2/2/97 12:35:00 AM
2/2/97 12:25:00 AM
------------------
        600 seconds difference

        Is there a simple way of accomplishing this?

        Thanks -                            

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

  St. Louis, Missouri - USA                    http://www.i1.net/~jimoshea
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

 
 
 

Calculating deltas between date & time stamps

Post by Jim Denn » Sun, 09 Mar 1997 04:00:00




Quote:> I'm writing a script that requires me to calculate the difference in
> seconds between two time and dates stamps.  An example of this is:
> 2/2/97 12:35:00 AM
> 2/2/97 12:25:00 AM
>  ------------------
>  600 seconds difference

           Is there a simple way of accomplishing this?

           Thanks -                            

        Use the GNU date command:

        $ date -d "2/2/97 12:35:00 AM" +%s
        854915700

        To do the whole thing use something like:

        echo $(( $(date -d "2/2/97 12:35:00 AM" +%s) \
                - $(date -d "2/2/97 12:25:00 AM" +%s) ))

        expr `date -d "2/2/97 12:35:00 AM" +%s` \
                - ` date -d "2/2/97 12:25:00 AM" +%s) `

        (note:  Korn/Bash $(( ... )) is aritmethic expression
        and $( ... ) is POSIX equivalent of backtick operator.

        These examples work under bash and ksh.

--


Starshine Technical Services              http://www.starshine.org


        Key fingerprint =  2524E3FEF0922A84  A27BDEDB38EBB95A

 
 
 

1. Calculating deltas between date & time stamps

I'm writing a script that requires me to calculate the difference in
seconds between two time and dates stamps.  An example of this is:

2/2/97 12:35:00 AM
2/2/97 12:25:00 AM
------------------
        600 seconds difference

        Is there a simple way of accomplishing this?

        Thanks -                            

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

  St. Louis, Missouri - USA                    http://www.i1.net/~jimoshea
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

2. SMP Linux on Dual PII

3. Date and Time stamp to hundredths of seconds?

4. Porting problems 2.3->2.4

5. serielle Com && Time Stamp Counter

6. x86 video config [Answer]

7. Changing File Modified Time/Date Stamp

8. CANON printing problems

9. synchronize date/time stamp with ftp server

10. Changing File Modified Time/Date Stamp

11. How do you reset file date time stamp

12. time/date stamp via #includes?

13. automatic time/date stamping on compile