Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subtracting Times 1

Status
Not open for further replies.

rik1551

IS-IT--Management
Sep 14, 2001
10
GB
Hi everyone,

I need to be able to write into a ksh script, a function that can look at 2 24 hour time variables and work out the difference between them.

e.g

job1 runs at 21:00
job2 runs at 01:00

diff = +04:00 hours

I would also need negative numbers i.e where job1 runs after job2

can anybody help?

cheers

Rik

 
The idea is to get UTC time (seconds since 1970/01/01 00:00:00)

if your `date' command suprts %s (UTC) then:
u@h:w$ job1_time=`date +%s`
u@h:w$ job2_time=`date +%s`
u@h:w$ delay=$((job2_time-job1_time))
u@h:w$ echo $((delay/60/60)):$((delay/60%60)):$((delay%60))


verified with
ksh --version
version sh (AT&T Labs Research) 1993-12-28 m
__
___
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top