DTRUNC: Returning the Start of a Date Period for a Given Date

How to:

Given a date or timestamp and a component, DTRUNC returns the first date within the period specified by that component.


Top of page

x
Syntax: How to Return the First Date of a Date Period
DTRUNC(date_or_timestamp, date_period)

where:

date_or_timestamp

Date or date-time

Is the date or timestamp of interest.

date_period

Is the period whose starting date you want to find. Can be one of the following:

  • DAY, returns day of the month (1-31).
  • YEAR, returns year (1-9999).
  • MONTH, returns month (1-12).
  • QUARTER, returns quarter (1-4).


Example: Returning the First Date in a Date Period

In the following request against the WF_RETAIL data source, DTRUNC returns the first date of the quarter given the start date of the employee:

DEFINE FILE WF_RETAIL
QTRSTART/YYMD = DTRUNC(START_DATE, QUARTER); 
END
TABLE FILE WF_RETAIL
PRINT START_DATE QTRSTART AS 'Start,of Quarter'
BY EMPLOYEE_NUMBER 
WHERE EMPLOYEE_NUMBER CONTAINS 'AH'
ON TABLE SET PAGE NOPAGE
END 

The output is:


WebFOCUS