[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Calculating difference between dates

> does anybody know how it would be possible to calculate the difference
> between two dates with a shell or awk script, for example from 15:30:23
> to 17:29:01?

Those aren't dates. Those are times, but the following should work either

try:  date -d "15:30:23" +"%s"

This will give you the number of seconds from 1970 until the time you
specify until today. So you can do something like:

sooner=`date -d "15:30:23" +"%s"`
later=`date -d "17:29:01" +"%s"`
seconds=`expr "$later" - "$sooner"`

and $seconds should contain the difference, in seconds.

BTW, this is all in plain 'ol shell script.

- Joe

Reply to: