- Datetime subtraction operator
- Last Updated: January 18, 2024
- 1 minute read
- OpenEdge
- Version 12.8
- Documentation
Subtracts a number of milliseconds from a DATETIME or a DATETIME-TZ to produce another DATETIME or DATETIME-TZ, or subtracts one DATETIME or DATETIME-TZ from another to produce an INT64 result in milliseconds.
Syntax
|
|
- datetime
- An expression that evaluates to a DATETIME value.
- milliseconds
- An expression that evaluates to an integer value specifying a number of milliseconds.
- datetime-tz
- An expression that evaluates to a DATETIME-TZ value.
Example
This
example returns the date and time exactly 24 hours ago (dtTime).
It then recalculates the number of hours (iHours)
from the number of milliseconds (iMsec) since then
and displays the result:
|
Notes
- To
get the number of days between two DATETIME or DATETIME-TZ variable
values, use the DATE function.
For example:
num-days = DATE(dt2) - DATE(dt1)This operation does not take the time portion into account.
To ensure the correct result when working with two DATETIME-TZ values, convert one of the values to the time zone of the other. For example:
ASSIGN temp-dttz = dt1 TIMEZONE(temp-dttz) = TIMEZONE(dt2) num-days = DATE(dt2) - DATE(temp-dttz). - To subtract a specific number of days and milliseconds from
a DATETIME, use the DATETIME function.
For example:
new-datetime = DATETIME( DATE(old-datetime) - days, MTIME (old-datetime) - milliseconds ).The DATETIME function ensures the time portion remains within a valid range by borrowing a day from the date portion, when necessary.
- To subtract a specific number of days and milliseconds from
a DATETIME-TZ, use the DATETIME-TZ function. For
example:
new-datetime-tz = DATETIME-TZ( DATE(old-datetime-tz) - days, MTIME (old-datetime-tz) - milliseconds, TIMEZONE(old-dateime-tz) ).The DATETIME-TZ function ensures the time portion remains within a valid range by borrowing a day from the date portion, when necessary.
See also
- Date subtraction operator, + Datetime addition operator, ADD-INTERVAL function, DATETIME function, DATETIME-TZ function, INTERVAL function