DPART: Extracting a Component From a Date

How to:

The DPART function extracts a specified component from a date field and returns it in numeric format.

Since Dialogue Manager interprets a date as alphanumeric or numeric, and DPART requires a standard date stored as an offset from the base date, do not use DPART with Dialogue Manager unless you first convert the variable used as the input date to an offset from the base date.

Available Languages: reporting, Maintain

Syntax: How to Extract a Date Component and Return It in Integer Format

DPART (datevalue, 'component', output)

where:

datevalue

Date

Is a full component date.

component

Alphanumeric

Is the name of the component to be retrieved enclosed in single quotation marks. Valid values are:

For year: YEAR, YY

For month: MONTH, MM

For day: DAY, For day of month: DAY-OF-MONTH, DD.

For weekday: WEEKDAY, WW.

For quarter: QUARTER, QQ

output

Integer

Is the field that contains the result, or the integer format of the output value enclosed in single quotation marks.

Example: Extracting Date Components in Integer Format

The following request against the VIDEOTRK data source uses the DPART function to extract the year, month, and day component from the TRANSDATE field:

DEFINE FILE
 VIDEOTRK                       
 YEAR/I4 = DPART(TRANSDATE, 'YEAR', 'I11');
 MONTH/I4 = DPART(TRANSDATE, 'MM', 'I11'); 
 DAY/I4 = DPART(TRANSDATE, 'DAY', 'I11');  
END                                        
                                           
TABLE FILE VIDEOTRK                        
PRINT TRANSDATE YEAR MONTH DAY             
BY LASTNAME BY FIRSTNAME                   
WHERE LASTNAME LT 'DIAZ'                   
END

The output is:

LASTNAME         FIRSTNAME   TRANSDATE  YEAR  MONTH   DAY
--------         ---------   ---------  ----  -----   ---
ANDREWS          NATALIA     91/06/19   1991      6    19
                             91/06/18   1991      6    18
BAKER            MARIE       91/06/19   1991      6    19
                             91/06/17   1991      6    17
BERTAL           MARCIA      91/06/23   1991      6    23
                             91/06/18   1991      6    18
CHANG            ROBERT      91/06/28   1991      6    28
                             91/06/27   1991      6    27
                             91/06/26   1991      6    26
COLE             ALLISON     91/06/24   1991      6    24
                             91/06/23   1991      6    23
CRUZ             IVY         91/06/27   1991      6    27
DAVIS            JASON       91/06/24   1991      6    24