Performing date, time, and timestamp arithmetic using the Open Query File (OPNQRYF) command
Date, time, and timestamp values can be incremented, decremented, and subtracted. These operations might involve decimal numbers called durations.
- Durations
A duration is a number that represents an interval of time.
- Rules for date, time, and timestamp arithmetic
The only arithmetic operations that can be performed on date and time values are addition and subtraction. If a date or time value is the operand of addition, the other operand must be a duration.
- Subtracting dates
The result of subtracting one date (DATE2) from another (DATE1) is a date duration that specifies the number of years, months, and days between the two dates.
- Incrementing and decrementing dates
The result of adding a duration to a date or subtracting a duration from a date is itself a date.
- Subtracting times
The result of subtracting one time (TIME2) from another (TIME1) is a time duration that specifies the number of hours, minutes, and seconds between the two times.
- Incrementing and decrementing times
The result of adding a duration to a time or subtracting a duration from a time is itself a time. Any overflow or underflow of hours is discarded, thereby ensuring that the result is always a time.
- Subtracting timestamps
The result of subtracting one timestamp (TS2) from another (TS1) is a timestamp duration that specifies the number of years, months, days, hours, minutes, seconds, and microseconds between the two timestamps.
- Incrementing and decrementing timestamps
The result of adding a duration to a timestamp or subtracting a duration from a timestamp is itself a timestamp.
Parent topic:
Using Open Query File (OPNQRYF) command