Manipulating DATETIME Values
You can subtract most DATETIME values from each other.
Dates can be in any order and the result is either a positive or a negative INTERVAL value. The first DATETIME value determines the precision of the result, which includes the same time units as the first operand.
If the second DATETIME value has fewer fields than the first, the precision of the second operand is increased automatically to match the first.
DATETIME (2003-9-30 12:30) YEAR TO MINUTE
- DATETIME (2003-8-1 11) YEAR TO HOUR
Result: INTERVAL (60 01:30) DAY TO MINUTE
If the second DATETIME operand has more fields than the first (regardless of whether the precision of the extra fields is larger or smaller than those in the first operand), the additional time unit fields in the second value are ignored in the calculation.
DATETIME (2005-9-30) YEAR TO DAY
- DATETIME (10-1) MONTH TO DAY
Result: INTERVAL (-1) DAY TO DAY [assuming that the current
year is 2005]
You can compare two DATETIME values by using the mi_datetime_compare() function.