DTIME: Extracting Time Components From a Date-Time Value

How to:

Given a date-time value and time component keyword as input, DTIME returns the value of all of the time components up to and including the requested component. The remaining time components in the value are set to zero. The field to which the time component is returned must have a time format that supports the component being returned.

Syntax: How to Extract a Time Component From a Date-Time Value

DTIME(datetime, component)

where:

datetime

Date-time

Is the date-time value from which to extract the time component. It can be a field name or a date-time literal. It must provide a full component date.

component

Keyword

Valid values are:

  • TIME. The complete time portion is returned. Its smallest component depends on the input date-time format. Nanoseconds are not supported or returned.
  • HOUR. The time component up to and including the hour component is extracted.
  • MINUTE. The time component up to and including the minute component is extracted.
  • SECOND. The time component up to and including the second component is extracted.
  • MILLISECOND. The time component up to and including the millisecond component is extracted.
  • MICROSECOND. The time component up to and including the microsecond component is extracted.

Example: Extracting Time Components

The following request defines two date-time fields:

  • TRANSTIME contains the extracted time components from TRANSDATE down to the minute.
  • TRANSTIME2 extracts all of the time components from the literal date-time value 2018/01/17 05:45:22.777888.
DEFINE FILE VIDEOTR2
TRANSTIME/HHISsm = DTIME(TRANSDATE, MINUTE);
TRANSTIME2/HHISsm = DTIME(DT(2018/01/17 05:45:22.777888), TIME);
END
TABLE FILE VIDEOTR2
SUM  TRANSTIME TRANSTIME2
BY MOVIECODE
BY  TRANSDATE 
WHERE MOVIECODE CONTAINS 'MGM'
ON TABLE SET PAGE NOLEAD
ON TABLE SET STYLE *
GRID=OFF,$
ENDSTYLE 
END

The output is shown in the following image.