Each of the interval provider types support the following arithmetic operations:
Operation | Description |
---|---|
TdInterval operator+ (TdInterval left, TdInterval right) | Each of the intervals supports addition to each other. The result of the operation is the same interval type. |
TdInterval Add (TdInterval left, TdInterval right) | Each of the intervals supports addition to each other. The result of the operation is the same interval type. |
TdInterval operator+ (TdInterval interval, Int32 value) | Only the single value interval types support this operator: TdIntervalYear, TdIntervalMonth, TdIntervalDay, TdIntervalHour, TdIntervalMinute and TdIntervalSecond. The operator is associative and the operand order may be exchanged. |
TdInterval operator- (TdInterval left, TdInterval right) | Each of the intervals supports subtraction from each other. The result of the operation is the same interval type. |
TdInterval Subtract (TdInterval left, TdInterval right) | Each of the intervals supports addition to each other. The result of the operation is the same interval type. |
TdInterval operator- (TdInterval interval, Int32 value) | Only the single value interval types support this operator: TdIntervalYear, TdIntervalMonth, TdIntervalDay, TdIntervalHour, TdIntervalMinute and TdIntervalSecond. The operator is not associative and the operand order may not be exchanged. |
TdInterval operator* (TdInterval interval, Int32 value) | Each of the intervals supports multiplication with an Int32. The result of the operation is the same interval type. Each of the interval components is multiplied by the Int32 value. The operator is associative and the operand order may be exchanged. |
TdInterval Multiply (TdInterval interval, Int32 value) | Each of the intervals supports multiplication with an Int32. The result of the operation is the same interval type. Each of the interval components is multiplied by the Int32 value. The operator is associative and the operand order may be exchanged. |
TdInterval operator/ (TdInterval interval, Int32 value) | Each of the intervals supports division by an Int32. The result of the operation is the same interval type. Each of the interval components is divided by the Int32 value. The operator is not associative and the operand order may not be exchanged. |
TdInterval Divide (TdInterval interval, Int32 value) | Each of the intervals supports division by an Int32. The result of the operation is the same interval type. Each of the interval components is divided by the Int32 value. The operator is not associative and the operand order may not be exchanged. |
If any of the interval operands are Null the result of all arithmetic operations is a Null interval.
All interval addition, subtraction and multiplication arithmetic operations will create a resultant interval with a maximum precision. The maximum precision for all intervals is 4 (four significant digits). All interval division arithmetic operations will create a resultant interval with the same precision as the interval dividend. The divisor must always be a numeric value.
All arithmetic operations will return an interval with a scale that is the greatest of either one of the interval operands. In operations with an interval and an integer, the scale will match the interval scale.
This example illustrates the resulting interval precision and scale from intervals that contain different precision and scale.
C# |
Copy Code |
---|---|
// Create an interval of 1 day, 20 hours, 10 minutes, 30 seconds and 25 microseconds // with a precision of 3 and a scale of 5 TdIntervalDayToSecond dts = new TdIntervalDayToSecond(1, 20, 10, 30, 20); // Multiply by 200 TdIntervalDayToSecond result = dts * 200; // Print out the result Console.WriteLine("The result of the multiplication is : {0}", result); // The output is: "The result of the multiplication is –> 368 03:00:00.00400" // The result has a precision of 4 and and scale of 5 // Add intervals with different precision and scale // Create an interval of 100 days, 20 hours, 10 minutes, 30 seconds and 2 microseconds // with a precision of 3 and a scale of 6 TdIntervalDayToSecond left = new TdIntervalDayToSecond(100, 20, 10, 30, 2); // Create an interval of 1 day, 15 hours, 1 minute, 30 seconds and 40000 microseconds // with a precision of 1 and a scale of 2 TdIntervalDayToSecond right = new TdIntervalDayToSecond(1, 15, 1, 30, 40000); // Add left and right TdIntervalDayToSecond result2 = left + right; // Print out the result Console.WriteLine("The result of the addition is : {0}", result2); // The output is: "The result of the addition is –> 102 11:12:00.040002" // The result has a precision of 4 and and scale of 6 |
Left Operand | Arith. Op | Right Operand | Result |
---|---|---|---|
Interval '200-02' Year To Month | + | Interval '10-11' Year To Month | Interval '211-01' Year To Month |
Interval '10:25:15.005' Hour To Second | / | 4 | Interval '2:36:18.751' Hour To Second |
Interval '908' Month | / | 12 | Interval '91' Month |
Interval '30:05.008' Minute To Second | - | Interval '300:30.00087' Minute To Second | Interval -'270:24.99287' Minute To Second |
Interval '100 20:10:30.500002' Day To Second | / | 200 | Interval '0 12:06:03.152500' Day To Second |
Interval '10:25:15.005' Hour To Second | * | 25 | Interval '260:31:15.125' Hour To Second |
Addition and subtraction arithmetic operations are supported among different interval types through support of implicit conversions - Interval Implicit Conversions.
The following are some examples of addition and subtraction of differing interval types:
Interval | Arith. Op | Interval | Result |
---|---|---|---|
Interval '300.0009' Second | + | Interval '100 20:10:30.000002' Day To Second | Interval '100 20:15:30.000902' Day To Second |
Interval '10:10' Hour To Minute | + | Interval '100 20:10:30.000002' Day To Second | Interval '101 06:20:30.000002' Day To Second |
Interval '10:25:15.005' Hour To Second | - | Interval '30:05.008' Minute To Second | Interval '9:55:09.997' Hour To Second |
Interval '20' Year | - | Interval '300-09' Year To Month | Interval -'280-09' Year To Month |
Interval arithmetic addition and subtraction operations are supported in the following provider specific types:
Provider specific types that only support time (TdTime, TdTimeWithTimeZone, TdPeriodTime, TdPeriodTimeWithTimeZone) will only support interval arithmetic operations with the following interval types: