HNAME: Retrieving a Date-Time Component in Alphanumeric Format

How to:

Available Languages: reporting, Maintain

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

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

HNAME(datetime, 'component', output)

where:

datetime

Date-time

Is the date-time value from which a component value is to be extracted, the name of a date-time field containing the value 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.

output

Alphanumeric, at least A2

Is the field that contains the result, or the format of the output value enclosed in single quotation marks. The format must be in alphanumeric format.

The function converts a month argument to an abbreviation of the month name and converts and all other components to strings of digits only. The year is always four digits, and the hour assumes the 24-hour system.

Example: Retrieving the Week Component in Alphanumeric Format (Reporting)

HNAME returns the week in alphanumeric format from the TRANSDATE field. Changing the WEEKFIRST parameter setting changes the value of the component.

SET WEEKFIRST = 7
TABLE FILE VIDEOTR2
PRINT CUSTID TRANSDATE AS 'DATE-TIME' AND COMPUTE
WEEK_COMPONENT/A10 = HNAME(TRANSDATE, 'WEEK', 'A10');
WHERE DATE EQ 2000;
END

When WEEKFIRST is set to seven, the output is:

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

When WEEKFIRST is set to three, the output is:

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

For details on WEEKFIRST, see the Developing Reporting Applications manual.

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

HNAME retrieves the day in alphanumeric format from the TRANSDATE field:

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

The output is:

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

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

HNAME extracts the day in alphanumeric format from DT1:

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