Upload
gosai83
View
219
Download
0
Embed Size (px)
Citation preview
7/27/2019 Subtraction of Minutes and Seconds
1/11
Subtraction of Hours and MinutesHow to subtract hours and minutes.
If the number of minutes being subtracted is more than the original
minutes, do the following:o Subtract 1 from the original number of hours.
o Increase the number of original minutes by 60.
Subtract the minutes.
Subtract the hours.
Example: What is 4 hours 11 minutes minus 2 hours 47 minutes.
The original number of minutes (11) is less than the 47 minutesbeing subtracted so:
o Subtract 1 from the original number of hours. (4 hours - 1hour = 3 hours)
o Increase the number of minutes by 60. (11 minutes + 60minutes = 71 minutes)
Subtract the minutes. (71 minutes - 47 minutes = 24 minutes)
Subtract the hours. (3 hours - 2 hours = 1 hour)
Answer: 1 hour 24 minutes
Subtraction of Minutes and SecondsHow to subtract minutes and seconds
If the number of seconds being subtracted is more than the originalseconds, do the following:
o Subtract 1 from the original number of minutes.
o Increase the number of original seconds by 60.
Subtract the seconds.
Subtract the minutes.
Example: What is 4 minutes 11 seconds minus 2 minutes 47 seconds.
The original number of seconds (11) is less than the 47 secondsbeing subtracted so:
7/27/2019 Subtraction of Minutes and Seconds
2/11
o Subtract 1 from the original number of minutes. (4 minutes -1 minute = 3 minutes)
o Increase the number of seconds by 60. (11 seconds + 60seconds = 71 seconds)
Subtract the seconds. (71 seconds - 47 seconds = 24 seconds)
Subtract the minutes. (3 minutes - 2 minutes = 1 minute)
Answer: 1 minute 24 seconds
Subtraction rules for DATE, TIME, and TIMESTAMP
The only arithmetic operation that can be performed on datetime values issubtraction. The subtraction operator can be used with datetime values only
when both operands are dates, or both operands are times, or both operands aretimestamps.
DATE
The result of subtracting one date (DATE2) from another (DATE1) is a dateduration that specifies the number of years, months, and days between the twodates. The data type of the result is DECIMAL(8,0). For example, the result ofDATE('3/15/2000') DATE('12/31/1999') is 00000215 (a duration of 0 years, 2months, and 15 days).
If DATE1 is greater than or equal to DATE2, DATE2 is subtracted from DATE1. IfDATE1 is less than DATE2, however, DATE1 is subtracted from DATE2, and thesign of the result is made negative. The following procedural description clarifiesthe steps involved in the operation result = DATE1 - DATE2.
If DAY(DATE2) DAY(DATE1)
then DAY(RESULT) = N + DAY(DATE1) - DAY(DATE2)
where N = the last day of MONTH(DATE2).
MONTH(DATE2) is then incremented by 1.
If MONTH(DATE2) MONTH(DATE1)
then MONTH(RESULT) = 12 + MONTH(DATE1) - MONTH(DATE2).
7/27/2019 Subtraction of Minutes and Seconds
3/11
YEAR(DATE2) is then incremented by 1.
YEAR(RESULT) = YEAR(DATE1) - YEAR(DATE2).
TIME
The result of subtracting one time (TIME2) from another (TIME1) is a timeduration that specifies the number of hours, minutes, and seconds between thetwo times. The data type of the result is DECIMAL(6,0). For example, the result of
TIME(11:02:26) TIME(00:32:56) is 102930 (a duration of 10 hours, 29minutes, and 30 seconds).
If TIME1 is greater than or equal to TIME2, TIME2 is subtracted from TIME1. IfTIME1 is less than TIME2, however, TIME1 is subtracted from TIME2, and the signof the result is made negative. The following procedural description clarifies thesteps involved in the operation result = TIME1 - TIME2.
If SECOND(TIME2) SECOND(TIME1)
then SECOND(RESULT) = 60 + SECOND(TIME1) - SECOND(TIME2).
MINUTE(TIME2) is then incremented by 1.
If MINUTE(TIME2) MINUTE(TIME1)
then MINUTE(RESULT) = 60 + MINUTE(TIME1) - MINUTE(TIME2).
HOUR(TIME2) is then incremented by 1.
HOUR(RESULT) = HOUR(TIME1) - HOUR(TIME2).
TIMESTAMP
The result of subtracting one timestamp (TS2) from another (TS1) is a timestampduration that specifies the number of years, months, days, hours, minutes,seconds, and microseconds between the two timestamps. The data type of theresult is DECIMAL(20,6).
If TS1 is greater than or equal to TS2, TS2 is subtracted from TS1. If TS1 is lessthan TS2, however, TS1 is subtracted from TS2 and the sign of the result is madenegative. The following procedural description clarifies the steps involved in theoperation result = TS1 - TS2:
If MICROSECOND(TS2)
7/27/2019 Subtraction of Minutes and Seconds
4/11
If MICROSECOND(TS2) > MICROSECOND(TS1)
then MICROSECOND(RESULT) = 1000000 + MICROSECOND(TS1) -MICROSECOND(TS2)
and SECOND(TS2) is incremented by 1.
The seconds and minutes part of the timestamps are subtracted as specified inthe rules for subtracting times. The date part of the timestamps is subtracted asspecified in the rules for subtracting dates.
9. Comparison and Subtraction of Time Intervals
The Easy Case - Conversions not needed
Here are two time intervals in cosmetic normal formal
T1 = 6 hours 35 minutes and 15 seconds
T2 = 8 hours 45 minutes and 30 seconds
The second time interval T2 has more hours, more minutes and seconds than the first T1. So
it is larger.
The subtraction
T2 = 8 hours 45 minutes and 30 seconds
T1 = 6 hours 35 minutes and 15 seconds __
T2 - T1 = 2 hours 10 minutes and 15 seconds
suggests T2 is 2 hours 10 minutes and 15 seconds more than T1.
Let us check that by an addition:
2 hours 10 minutes and 15 seconds
T1 = 6 hours 35 minutes and 15 seconds +
8 hours 45 minutes and 30 seconds = T2
Harder Cases - Conversions Needed
Here are two more time intervals
T1 = 7 hours 35 minutes and 15 seconds
T2 = 5 hours 45 minutes and 30 seconds
The first time interval T1 has 2 more hours than the second T2. Just one of those extra hours
by itself is larger than the minute and second part of the other time interval T2. So in this
case, the first time interval is more than (larger than) the second. Subtraction will say howmuch more.
7/27/2019 Subtraction of Minutes and Seconds
5/11
The first time interval T1 in its minutes and second portion has fewer minutes and fewer
seconds than the other time interval T2 . So the first column method for subtraction
introduced above would have us write:
The subtraction
T1 = 7 hours 35 minutes and 15 seconds
T2 = 5 hours 45 minutes and 30 seconds __
T2 - T1 = 2 hours ?? minutes and ?? seconds
If we avoid negative numbers or counts, we will have difficulty with the seconds and minute
entries in this subtraction. But the first time interval T1 has 2 more hours than the second T2.
Just one of those extra hours by itself is larger than the minute and second part of the other
time interval T2. That suggests a conversion:
1 hour = 59 minutes and 60 seconds and so 7 hours = 6 hours, 59 minutes and 60 seconds.
Now T1 = 7 hours 35 minutes and 15 seconds
= 6 hours, 59 minutes and 60 seconds + 35 minutes and 15 seconds
We want to subtract T2 = 5 hours 45 minutes and 30 seconds from the latter.
T1 = 6 hours, 59 minutes and 60 seconds + 35 minutes and 15 seconds
T2 = 5 hours 45 minutes and 30 seconds __
T1 - T2 = 1 hour 14 minutes and 30 seconds + 35 minutes and 15 seconds
That latter gives
T1 - T2 = 1 hour 49 minutes and 45 seconds
The latter gives how much, the first time length T1 is more than the other time interval T2.
Let us check that:
1 hour 49 minutes and 45 seconds
T2 = 5 hours 45 minutes and 30 seconds +
7 hours, 35 minutes and 15 seconds = T11 1
Observe the presence of carries in the minute and hours columns.
The foregoing calculations suggest a column method for subtraction when conversions are
needed.
First, write
T1 = 7 hours 35 minutes and 15 seconds
7/27/2019 Subtraction of Minutes and Seconds
6/11
T2 = 5 hours 45 minutes and 30 seconds __
as before, but with an extra line. The extra line is needed.
We will cross-out the 7 hours on the top line, and replace its by 6 hours, 59 minutes and 60seconds
on the second line. That gives
T1 = 7 hours 35 minutes and 15 seconds
6 hours, 59 minutes and 60 seconds
7/27/2019 Subtraction of Minutes and Seconds
7/11
Example B.
50 hours 23 minutes 17 seconds versus 34 hours 25 minutes 25 seconds.
Solution: The first time interval is larger as it has more hours than than first. The difference
isgive by first writing
hours mins secs
50 23 17
23 25 25 -
with an extra line since conversions will be needed in the minute and seconds column. Now
in place, cross-out the 50 and replace it by an entry of 49 hours, 59 minutes and 60 seconds in
line 2. That should give you
hours mins secs
50 23 17
49 59 60
23 25 25 -
Now continue the calculation in place to obtain the following:
hours mins secs
50 23 17 (line 1)
49 59 60 (line 2)
23 25 25 - (line 3)
26 57 52 (line 4)
Work: 17 + 60 - 25 = 17 + 35 = 52
23+ 59 - 25 = 23 + 37 = 57
49 - 26 = 23
The longer time interval should be 26 hours, 57 minutes and 52 seconds more than the
first. Finally, check that in place by verifying the original line 1 (no cross-out) is the sume oflines 3 and 4
Example C.
30 hours 35 minutes 13 seconds versus 30 hours 20 minutes 25 seconds.
Solution: Again, the first time interval is larger as it has more minutes than than first. The
difference is calculated by first writing
hours mins secs
30 35 13
7/27/2019 Subtraction of Minutes and Seconds
8/11
30 20 25 -
with an extra line since conversions will be needed in the minute and seconds column. Now
in place, cross-out the 35 in the minute column and replace it by an entry of 34 minutes and
60 seconds in line 2. That should give you
hours mins secs
30 35 13
34 60
30 20 25 -
Now continue the calculation in place to obtain the following:
hours mins secs
30 35 13 (line 1)34 60 (line 2)
30 20 25 - (line 3)
14 48 (line 4)
Work: 13 + 60 - 25 = 13 + 35 = 48
34 - 20 = 14
The longer time interval should be 14 minutes and 48 seconds more than the first. Finally,
check that in place by verifying the original line 1 (no cross-out) is the sum of lines 3 and 4
Example D.
55 hours 43 minutes 35 seconds versus 35 hours 13 minutes 55 seconds.
Solution: Again, the first time interval is larger as it has more hours than than first. The
difference is calculated by first writing
hours mins secs
55 43 35
35 13 55 -
with an extra line since conversions will be needed in the seconds column. No conversions
are needed elsewhere. The first line has more minutes than the last line. Now in place,
cross-out the 43 in the minute column and replace it by an entry of 42 minutes and 60
seconds in line 2. That should give you
hours mins secs
55 43 35
42 6035 13 55 -
7/27/2019 Subtraction of Minutes and Seconds
9/11
Now continue the calculation in place to obtain the following:
hours mins secs
55 43 3542 60
35 13 55 -
20 29 40
Work: 35 + 60 - 55 = 35 + 5 = 40
42 - 13 = 29
The longer time interval should be 20 hours, 29 minutes and 40 seconds more than the
first. Finally, check that in place by verifying the original line 1 (no cross-out) is the sum of
the last two lines.
Example D - Revisited
55 hours 43 minutes 35 seconds versus 35 hours 13 minutes 55 seconds.
Solution: Again, the first time interval is larger as it has more hours than than first. The
difference is calculated by first writing
hours mins secs
55 43 35
35 13 55 -
with an extra line since conversions will be needed in the seconds column. No
conversions are needed elsewhere.
In this second version of Example D, we will convert 55 hours into 54 hours, 59 minutes
and 60 seconds. That is not necessary because 43 minutes and 35 seconds is longer than
13 minutes and 55 seconds, and hence conversion of 43 minutes into 42 minutes and 60
seconds was good enough (and quicker). We doing this to compare and contrast the tworoutes for obtaining a solution. You need the experience.
The first line has more hours than the last line. Now in place, cross-out the 55 in the hour
column and replace it by an entry of 54 hours, 59 minutes and 60 seconds in line 2. That
should give you
hours mins secs
55 43 35
54 59 60
35 13 55 -
7/27/2019 Subtraction of Minutes and Seconds
10/11
Now continue the calculation in place to obtain the following:
hours mins secs
55 43 3554 59 60
35 13 55 -
20 29 40
1
Work: 35 + 60 - 55 = 35 + 5 = 40 as before
43 + 59 -13 = 43 + 46 = 89 or 1 hour and 29 minutes
(that gives a carry of 1 hour to add into the hours column
1+ 54 - 35 = 1 + 19 = 20
Again, the time interval should be 20 hours, 29 minutes and 40 seconds more than the
first.
In this second approach, the conversion of 55 hours into 54 hours, 59 minutes and 60
seconds was not wrong, but it the effect of introducing the conversion of 89 minutes into
the answer.
Without the conversion of 89 minutes into 1 hour and 29 minutes, the above calculation
would have given
hours mins secs
55 43 35
54 59 60
35 13 55 -
19 89 40
or 19 hours, 89 minutes and 40 seconds as a result, correct except it is not in cosmetic
normal form.
Example E.
25 hours 45 minutes 10 seconds versus 40 hours 18 minutes 55 seconds versus .
Solution: The second time interval has more hours than the first. So it is larger.
The difference is calculated by first writing
hours mins secs
40 18 55
25 45 10 -
7/27/2019 Subtraction of Minutes and Seconds
11/11
with an extra line since conversions will be needed. Now in place, 55 secs - 10 secs gives 45
secs.
In place that gives
hours mins secs
40 18 55
25 45 10 -
45
Now in place, cross-out the 40 in the hour column and replace it by an entry of 39 hours and
60 minutes in the extra line.
hours mins secs
40 18 5539 60
25 45 10 -
45
Now continue the calculation in place to obtain the following:
hours mins secs
40 18 55
39 60
25 45 10 -
14 33 45
Work: 18 + 60 - 45 = 18 + 15 = 33
39 - 25 = 14
The longer time interval should be 14 hours, 33 minutes and 45 seconds more than the
other. Finally, check that in place by verifying the original line 1 (no cross-out) is the sum of
the last two.
Remark: We could use negative numbers here.