# Thread: Calculating Time Difference When The Time Is Stored as an int

1. ## Calculating Time Difference When The Time Is Stored as an int

Right heres what I'm trying to do-

I'm making a function that recieves a 24 hour time as an int. For example "1300", for one o'clock and "1534", for 26 minutes to 4. What I want to do is get the number of minutes difference between the two values but have problems when I try to just take them away from each other because of the whole 60minutes in an hour problem.

Is there any way I can seperate the first two digits of the int passed to my function so that I can multiply them by 60 to get a difference that way? I can't use the time function to get the program to do it for me.

2. One way to skin that cat...
Code:
```    char str_time[] = "1534";
char *str_minutes = str_time + 2;

int hour, minute;

minute = atoi(str_minutes);
str_time[2] = NULL;
hour = atoi(str_time);

printf("hour = %d\n", hour);
printf("minute = %d\n", minute);```
gg

3. Divide it by 100 to get the "hours", mod it by 100 to get the "minutes".

Quzah.

4. Dammit of course. Thanks quzah got it done. Knew it had to be something really simple.

Popular pages Recent additions