EXTRCT (Extract Date/Time/Timestamp)

Free-Form Syntax (not allowed - use the %SUBDT built-in function)
Code Factor 1 Factor 2 Result Field Indicators
EXTRCT (E)   Date/Time: Duration Code Target _ ER _
The EXTRCT operation code will return one of:
  • The year, month or day part of a date or timestamp field
  • The hours, minutes or seconds part of a time or timestamp field
  • The microseconds part of the timestamp field

The EXTRCT operation only supports extracting microseconds (6 fractional seconds) from a timestamp field. If you want to extract a different number of fractional seconds, use the %SUBDT built-in function.

to the field specified in the result field.

The Date, Time or Timestamp from which the information is required, is specified in factor 2, followed by the duration code. The entry specified in factor 2 can be a field, subfield, table element, or array element. The duration code must be consistent with the Data type of factor 2. See Date Operations for valid duration codes.

Factor 1 must be blank.

The result field can be any numeric or character field, subfield, array/table element. The result field is cleared before the extracted data is assigned. For a character result field, the data is put left adjusted into the result field.
Note: When using the EXTRCT operation with a Julian Date (format *JUL), specifying a duration code of *D will return the day of the month, specifying *M will return the month of the year. If you require the day and month to be in the 3-digit format, you can use a basing pointer to obtain it. See Figure 3 for an example of obtaining the Julian format.

To handle EXTRCT exceptions (program status code 112), either the operation code extender 'E' or an error indicator ER can be specified, but not both. For more information on error handling, see Program Exception/Errors.

For more information, see Date Operations.

Figure 1. EXTRCT Operation
     D LOGONDATE       S               D
     D DATE_STR        S             15
     D MONTHS          S              8    DIM(12) CTDATA
     C*0N01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq....
      * Move the job date to LOGONDATE.  By default, LOGONDATE has an *ISO
      * date format, which contains a 4-digit year.  *DATE also contains a
      * 4-digit year, but in a different format, *USA.
     C     *USA          MOVE      *DATE         LOGONDATE
      *
      * Extract the month from a date field to a 2-digit field
      * that is used as an index into a character array containing
      * the names of the months.  Then extract the day from the
      * timestamp to a 2-byte character field which can be used in
      * an EVAL concatenation expression to form a string.
      * For example, if LOGONDATE is March 17, 1996, LOGMONTH will
      * contain 03, LOGDAY will contain 17, and DATE_STR will contain
      * 'March 17'.
     C                   EXTRCT    LOGONDATE:*M  LOGMONTH          2 0
     C                   EXTRCT    LOGONDATE:*D  LOGDAY            2
     C                   EVAL      DATE_STR = %TRIMR(MONTHS(LOGMONTH))
     C                                        + ' ' + LOGDAY
     C                   SETON                                        LR
** CTDATA MONTHS
January
February
March
April
May
June
July
August
September
October
November
December