## Calculating deltas between date & time stamps

### 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
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

### Calculating deltas between date & time stamps

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

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
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-