DTPART: Returning a Date or Date-Time Component in Integer Format

How to:

Given a date in standard date or date-time format and a component, DTPART returns the component value in integer format.


Top of page

x
Syntax: How to Return a Date or Date-Time Component in Integer Format
DTPART(date, component)

where:

date

Date or date-time

Is the date in standard date or date-time format.

component

Keyword

Is the component to extract in integer format. Valid components (and values) are:

  • YEAR (1-9999).
  • QUARTER (1-4).
  • MONTH (1-12).
  • WEEK (of the year, 1-53). This is affected by the WEEKFIRST setting.
  • DAY (of the Month, 1-31).
  • DAY_OF_YEAR (1-366).
  • WEEKDAY (day of the week, 1-7). This is affected by the WEEKFIRST setting.
  • HOUR (0-23).
  • MINUTE (0-59).
  • SECOND (0-59.)
  • MILLISECOND (0-999).
  • MICROSECOND (0-999999).


Example: Extracting the Quarter Component as an Integer

The following request against the WF_RETAIL data source extracts the QUARTER component from the employee start date:

DEFINE FILE WF_RETAIL
QTR/I2 = DTPART(START_DATE, QUARTER); 
END
TABLE FILE WF_RETAIL
PRINT START_DATE QTR AS Quarter
BY  EMPLOYEE_NUMBER 
WHERE EMPLOYEE_NUMBER CONTAINS 'AH'
ON TABLE SET PAGE NOPAGE
END 

The output is:


WebFOCUS