How to: |
Given two dates in standard date or date-time formats, DTIFF returns the number of given component boundaries between the two dates. The returned value has integer format for calendar components or double precision floating point format for time components.
DTDIFF(end_date, start_date, component)
where:
Date or date-time
Is the ending full-component date in either standard date or date-time format. If this date is given in standard date format, all time components are assumed to be zero.
Date or date-time
Is the starting full-component date in either standard date or date-time format. If this date is given in standard date format, all time components are assumed to be zero.
Keyword
Is the component on which the number of boundaries is to be calculated. For example, QUARTER finds the difference in quarters between two dates. Valid components (and acceptable values) are:
The following request against the WF_RETAIL data source calculates employee age when hired:
DEFINE FILE WF_RETAIL YEARS/I9 = DTDIFF(START_DATE, DATE_OF_BIRTH, YEAR); END TABLE FILE WF_RETAIL PRINT START_DATE DATE_OF_BIRTH YEARS AS 'Hire,Age' BY EMPLOYEE_NUMBER WHERE EMPLOYEE_NUMBER CONTAINS 'AA' ON TABLE SET PAGE NOPAGE END
The output is: