time difference

Hello

could anyone please tell me how to find out that the difference between the two times is less than equal to one hour e-g

13:32:45.96 - 13:30:10.83 = 0 hours, 2 minits, 35 seconds and 13 mseconds

Thanks
You can try converting a time into the smallest unit of measurement, i.d. convert it to milliseconds. Then you can subtract the two times and convert the result back into the standard format.

02:02:05.10 would be 100 milliseconds plus 5*1000 plus 02*60*1000 etc.
You could also make each time unit its own variable and subtract each.

for example...

int newHour, newMinute, newSecond, newMSecond;

int hour1 = 13;
int minute1 = 32;
etc....

int hour2 = 13;
int minute2 = 30;
etc....

newHour = hour1 - hour 2;
newMinute = minute1 - minute 2;
etc...
Thank you guys but is there any standard function in C++ for carrying out such operations or to avoid doing it manually as much as possible?
This may be what you're looking for, but I can't really help you with that because I'm not sure what the type time_t is:

http://www.cplusplus.com/reference/clibrary/ctime/difftime/
Last edited on
Thanks toexii. Let me try this code
Topic archived. No new replies allowed.