Date Operations

The date operations are shown in the following table.

Table 64. Date Operations
Operation Traditional Syntax Free-Form Syntax
Add Duration ADDDUR (Add Duration) + operator
Extract EXTRCT (Extract Date/Time/Timestamp) %SUBDT (Extract a Portion of a Date, Time, or Timestamp)
Subtract Duration SUBDUR (Subtract Duration) - operator or %DIFF (Difference Between Two Date, Time, or Timestamp Values)
Convert date/time/timestamp to character MOVE (Move) or MOVEL (Move Left) %CHAR (Convert to Character Data)
Convert date/time/timestamp to numeric MOVE (Move) or MOVEL (Move Left) %DEC (Convert to Packed Decimal Format)
Convert character/numeric to date MOVE (Move) or MOVEL (Move Left) %DATE (Convert to Date)
Convert character/numeric to time MOVE (Move) or MOVEL (Move Left) %TIME (Convert to Time)
Convert character/numeric/date to timestamp MOVE (Move) or MOVEL (Move Left) %TIMESTAMP (Convert to Timestamp)
Move date/time to timestamp MOVE (Move) or MOVEL (Move Left) date + time
Test TEST (Test Date/Time/Timestamp)
Number of Years %YEARS (Number of Years)
Number of Months %MONTHS (Number of Months)
Number of Days %DAYS (Number of Days)
Number of Hours %HOURS (Number of Hours)
Number of Minutes %MINUTES (Number of Minutes)
Number of Seconds %SECONDS (Number of Seconds)
Number of Microseconds %MSECONDS (Number of Microseconds)

Date operations allow you to work with dates, times, and timestamp fields and character or numeric fields that represent dates, times, and timestamps. You can:

To add or subtract a duration, you can use the + or - operator in free-form syntax or the ADDDUR or SUBDUR operation code in traditional syntax. The following table shows the built-in functions that you use in free-form syntax and the duration codes that you use in traditional syntax.

Table 65. Built-In Functions and Duration Codes
Unit Built-In Function Duration Code
Year %YEARS *YEARS or *Y
Month %MONTHS *MONTHS or *M
Day %DAYS *DAYS or *D
Hour %HOURS *HOURS or *H
Minute %MINUTES *MINUTES or *MN
Second %SECONDS *SECONDS or *S
Microsecond %MSECONDS *MSECONDS or *MS

For example, you can add 23 days to an existing date in either of the following ways:

C                   ADDDUR    23:*D         DUEDATE

 /FREE
     newdate = duedate + %DAYS(23)
 /END-FREE

To calculate the duration between two dates, times, or timestamps, you can use the %DIFF built-in function in free-form syntax or the SUBDUR operation code in traditional syntax. In either case, you must specify one of the duration codes shown in Table 65.

The duration is given in complete units, with any remainder discarded. A duration of 59 minutes, expressed in hours, is 0. A duration of 61 minutes, expressed in hours, is 1.

The following table shows additional examples, using the SUBDUR operation code. The %DIFF built-in function would give the same results.

Table 66. Resulting Durations Using SUBDUR
Duration Unit Factor 1 Factor 2 Result
Months 1999-03-28 1999-02-28 1 month
1999-03-14 1998-03-15 11 months
1999-03-15 1998-03-15 12 months
Years 1999-03-14 1998-03-15 0 years
1999-03-15 1998-03-15 1 year
1999-03-14-12.34.45.123456 1998-03-14-12.34.45.123457 0 years
Hours 1990-03-14-23.00.00.000000 1990-03-14-22.00.00.000001 0 hours


[ Top of Page | Previous Page | Next Page | Contents | Index ]