• 03-29-2002
JCCC
I am new to the programming field. I have been looking for examples of, or resources to the adding or subtracting of time variables in C/C++.

For example: given the time 20:30 Monday night and 04:30 Tuesday morning what is the difference?
Also adding 14:30 + 30:00 = 44:30.

I'm just looking for a starting place. All the time functions I've come across only have to do with obtaining the current date and time from the operating system. I'm looking to build a program that can manipulate given times somewhat like what an employer would need for managing a timeclock (I'm not an employer).

Thanx,

JCCC
• 03-29-2002
sigma
Use a circular class to implement it. That is, when a value like the hours goes above 24, it resets the hours to 0 and increments you day variable, if you have one.

On a project, we had to do alot of time manipulations. We used seconds as the units so we did not have to worry with carrying over the minutes and hours.
• 03-29-2002
JCCC
Does anyone have an example or a resource of samples?

JCCC
• 03-29-2002
Shiro
You need the modulo operator, this operator gets the remainder.

7 % 3 = 1

(7 / 3 = 2, 2 * 3 = 6, 7 - 6 = 1)

Example for time calculations:

20 hr + 6 hr = 26 hr
26 hr % 24 hr = 2 hr
26 hr / 24hr = 1 day

59 min + 3 min = 62 min
62 min % 60 min = 2 min
62 min / 60 min = 1 hr

so

20:59 + 6:3 = 3:2