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

How to:

Available Languages: reporting, Maintain

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
 
1237
1118
2000/02/05 03:30
2000/06/26 05:45
5
26
 

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

HPART extracts the day in integer format from DT1:

MAINTAIN FILE DATETIME
FOR 1 NEXT ID INTO STK;
COMPUTE
DAY_COMPONENT/I2 = HPART(STK.DT1,'DAY',DAY_COMPONENT);
TYPE "STK(1).DT1 = <STK(1).DT1";
TYPE "DAY_COMPONENT = <DAY_COMPONENT";
END