HPART: Retrieving a Date-Time Component as a Numeric Value

How to:

The HPART function extracts a specified component from a date-time value and returns it in numeric format.

Syntax: How to Retrieve a Date-Time Component in Numeric Format

HPART(datetime, 'component', output)

where:

datetime

Date-time

Is the date-time value from which the component is to be extracted, the name of a date-time field that contains the value, or an expression that returns the value.

component

Alphanumeric

Is the name of the component to be retrieved enclosed in single quotation marks. For a list of valid components, see Arguments for Use With Date and Time Functions.

output

Integer

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

Example: Retrieving the Day Component in Numeric Format (Reporting)

HPART retrieves the day in integer format from the TRANSDATE field:

TABLE FILE VIDEOTR2
PRINT CUSTID TRANSDATE AS 'DATE-TIME' AND COMPUTE
DAY_COMPONENT/I2 = HPART(TRANSDATE, 'DAY', 'I2');
WHERE DATE EQ 2000;
END

The output is:

CUSTID  DATE-TIME         DAY_COMPONENT
------  ---------         -------------
1118    2000/06/26 05:45             26
1237    2000/02/05 03:30              5