Computing.Net > Forums > Unix > Time calculation

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Time calculation

Reply to Message Icon

Name: Xerex
Date: August 16, 2004 at 15:36:05 Pacific
OS: UNIX
CPU/Ram: Solaris
Comment:

Hi,

If I were to script the whole thing by splitting the time string into its component parts..I am not that familiar with this. Can somebody help me through this? Here's another examle I wan't to do. Please see below: My time is in 24 hrs. setting. I just want to deduct the time 05:22 a.m. to 11:23 a.m. to get the hr. difference. Thanks

05:22.I
11:23.O
total hrs. rendered: ???

12:00.I
15:59.O
total hrs. rendered: ???




Sponsored Link
Ads by Google

Response Number 1
Name: Wolfbone
Date: August 17, 2004 at 06:10:28 Pacific
Reply:

If your times are in 24hr format, don't put 'a.m.' after them! Assuming the '.I' and '.O' are not part of your time strings:

dm=$((${t2#*:}+60*${t2%:*}-${t1#*:}-60*${t1%:*}))

sets 'dm' to the (possibly -ive) difference in minutes between t2 (latest) and t1 (earliest)

if ((dm < 0)) then dm=$((dm+24*60)); fi;

compensates for any pair of times spanning the boundary of a day.

print "$((dm/60))h $((dm%60))m"

gives the elapsed time eg. '2h 24m'.


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Time calculation

script execution time calculation www.computing.net/answers/unix/script-execution-time-calculation/7329.html

Calculating Time www.computing.net/answers/unix/calculating-time/6225.html

retreive the date with the time --URGENT www.computing.net/answers/unix/retreive-the-date-with-the-time-urgent/2933.html