Computing.Net > Forums > Unix > Calculating Time

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.

Calculating Time

Reply to Message Icon

Name: Xerex
Date: May 6, 2004 at 22:54:09 Pacific
OS: UNIX Solrais ( SUN OS)
CPU/Ram: ULTRA 5
Comment:

Hi Everyone,

Do anybody now how to calculate the time say for example the time rendered by an employee at work. What arithemetic commands should I use? Say for example:

Time in 2:00:00
Time out 6:00:00
Time in 7:30:00
Time out 10:30:00

Total Hours worked: ?

Thanks!

Xerex



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: May 7, 2004 at 09:03:26 Pacific
Reply:

Xerex:

dealing with dates and time in Unix is not much fun. Check out this thread:


http://computing.net/cgi-bin/printer.pl?5223|unix

Regards,

Nails



0

Response Number 2
Name: WilliamRobertson
Date: May 7, 2004 at 14:52:21 Pacific
Reply:

That was a fun thread.

If you have access to gawk (the GNU version of awk) it comes with mktime (which converts a date string to a number of seconds since 01 Jan 1970) and strftime (which converts back). For an example see shift_date.awk.

You can also script the whole thing yourself by splitting the time string into its component parts and using modulus ("%"), e.g. in ksh:

$ print $(( 75 % 60 ))
15

$ print $(( 75 / 60 ))
1


0

Response Number 3
Name: Xerex
Date: May 14, 2004 at 21:41:06 Pacific
Reply:

Hi,

Thanks Nails. I got my mind twisted with this time calculation. :) But it was enriching.

Rex


0

Sponsored Link
Ads by Google
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: Calculating Time

Calculate time taken in a script www.computing.net/answers/unix/calculate-time-taken-in-a-script/2476.html

Calculating time difference www.computing.net/answers/unix/calculating-time-difference/6988.html

calculate elapsed time www.computing.net/answers/unix/calculate-elapsed-time-/5425.html