# It's a question of time ...

This is a discussion on It's a question of time ... within the C Programming forums, part of the General Programming Boards category; Hi guys, i would like to convert a 4 digit number (eg 0824) into a time so that i can ...

1. ## It's a question of time ...

Hi guys,

i would like to convert a 4 digit number (eg 0824) into a time so that i can find the length of time between two times.
=> so 0824 and 0927 gives 1 hour and 3 minutes

i have found a function in the time.h library => difftime=(time_t timeB, time_t timeA)
but im unsure as to how to declare the numbers etc.

if anyone has any ideas, or good sites for information, i would be very grateful.

thanks

2. since you don't seem to be using seconds you can create a function to convert both times to minutes then subtract the clock out time from the clock in time to get minutes worked.

ex: 0927 = 567 minutes
0824 = 504 minutes

567 - 504 = 63 minutes

hope that helped,
-michael

3. great - thanks, it now works like that

but i havent agot a clue how i can display integers with a '0' in front.
i.e. 8 is displayed as 08

does any body have an idea?

thanks

4. Code:
printf("%02d",myInt);

5. Of course !!! i shudda known that!!!

Thanks alot anyway, Salem, saved me once again!!!