This blog is part of unitarium.com site where you can find unit converters, calculators and other information focused on units of measurement. See menu on the left.

## Posts Tagged ‘algorithm’

### Adding time – Algorithm 2

Wednesday, July 8th, 2009

Adding or subtracting time – Algorithm 2.

Previous algorithm is described here: Adding Time

Are you looking for adding time calculator online? See our online tool : Hour Calculator

Step 1 – Convert your data (time) to the smallest unit (minutes or seconds)
Step 3 – Convert obtained result back to the desired format

Step 1
“The smallest unit” means that if your data is given without seconds,e.g. 2:10 (two hours, ten minutes),
there is no need to convert hours to seconds because the smallest unit is a minute.

How to convert minutes to seconds, hours to minute and hours to seconds?
To convert minutes to seconds, simply multiply number of minutes by 60 (there is 60 seconds in one minute).
To convert hours to minutes, multiply number of hours by 60 (there is 60 minutes in an hour).
To convert hours to seconds multiply number of hours by 3600 (there is 60 seconds in each minute and 60
minutes in each hour, so 60*60 = 3600)

Step 2
no comments needed, I hope. This is simple arithmetic addition (or subtraction)

Step 3
This is the hardest step of this algorithm. To perform minutes to hours or
seconds to minute conversion, we have to find quotient (integer part) and reminder (‘left over’ amount)
of the division by 60 (or 3600). How to calculate quotient and reminder – see examples.

Example 1

T1 = 10:20, T2 = 1:50 – both values could be minutes:seconds or hours:minutes but let’s assume hours and minutes.

Step 1 – Change hours and minutes to minutes (smallest unit is minute):
T1 = 10:20 = 10*60 + 20 = 620 minutes
T2 = 1:50 = 1*60 + 50 = 110 minutes

T1 + T2 = 620 + 110 = 730 minutes

Step 3 – Change minutes to hours and minutes:
To convert minutes into hours and minutes, we have to divide number of minutes by 60 (number of minutes in one hour)
730/60 => quotient = 12, reminder = 10
How to calculate the quotient?
Simply, divide the numbers and throw decimal part away (730/60 = 12.16666…, so the quotient is 12)
How to calculate the reminder?
Simply, multiply quotient by divisor (12*60) and subtract obtained result from the divident (730 – 720 = 10)
or multiply thrown away decimal part by the divisor (60*0.166666… = 10)

The answer is 12 hours and 10 minutes (You can check the result using Hour Minute Calculator)

Example 2 (dealing with hours, minutes and seconds)

T1 = 10:20:25, T2 = 1:50:45

Step 1 – Converting hours, minutes and seconds to seconds (smallest unit is second):
T1 = 10:20:25 = 10*60*60 + 20*60 + 25 = 36000 + 1200 + 25 = 37225 seconds
T2 =  1:50:45 = 1*60*60 + 50*60 + 45 = 3600 + 3000 + 45 = 6645 seconds

T1 + T2 = 43870 seconds

Step 3 – Converting seconds to hours, minutes and seconds:
Method 1 – finding number of hours and seconds first.
43870/3600 => quotient = 12, reminder = 670 (how to find quotient and reminder – see Example 1)
So, we get 12 hours and 670 seconds. 670 seconds equals to 11 minutes and 10 seconds (why? – try to guess :))
So, the answer is 12 hours, 11 minutes and 10 seconds.
Method 2 – finding number of minutes and seconds first.
43870/60 => quotient = 731, reminder = 10
that means, we have 731 minutes and 10 seconds. 731 minutes is equal to 12 hours and 11 minutes
(how to convert minutes into hours and minutes – see example 1)
So, method 2 gives us the same result: 12 hours, 11 minutes, 10 seconds. (Check the result using Hour Minute Second Calculator)

Notice, that in the algorithm described above there is almost no difference between adding and subtracting.
The only difference can be found in step 2 and it is simple arithmetic calculation.

Monday, July 6th, 2009

Adding or subtracting time given in hours:minutes:seconds [hh:mm:ss] format.

Are you looking for adding time calculator online? See our online tool : Hour Calculator

Algorithm 1

Add hours, minutes,seconds saparately then, if number minutes or seconds exceeds 60 or are less then 0, adjust the answer.

Example 1 (Adding) – Let’s add 2:45:10(two hours, fourty five minutes, ten seconds) and 1:10:05

• Hours = 2 + 1 = 3
• Minutes = 45 + 10 = 55
• Seconds = 10 + 5 = 15

Our answer is 3 hours, 55 minutes, 15 seconds

Example 2 (Subtracting) – Let’s subtract the times form Example 1

• Hours = 2 – 1 = 1
• Minutes = 45 – 10 = 35
• Seconds 10 – 5 = 5

The answer is 1 hour, 35 minutes, 5 seconds

• Hours = 2 + 1 = 3
• Minutes = 30 + 45 = 75 (75 minutes is 1 hour and 15 minutes because 75 – 60 = 15)
• Seconds = 10 + 55 = 65 (1 minute and 5 seconds)

Because number of minutes and number of seconds are greater then 60, we have to adjust (by adding 1) the number of hours and minutes, so the answer is 4 hours, 16 minutes and 5 seconds.

Example 4 (subtracting with adjusting time). Let’s subtract time from Example 3

• Hours = 2 – 1 = 1
• Minutes = 30 – 45 = -15  (-1 hour + 45 seconds)
• Seconds = 10 – 55 = – 45 (-1 minute + 15 seconds)

Because number of minutes (and seconds) is less then zero we have to adjust number of hours (and minutes) by subtracting 1. The answer is 0 hours, 44 minutes, 15 seconds.

Another algorithm for adding time is available here Adding Time – Algorithm 2