HINPUT: Converting an Alphanumeric String to a Date-Time Value

How to:

Available Languages: reporting, Maintain

The HINPUT function converts an alphanumeric string to a date-time value.

Syntax: How to Convert an Alphanumeric String to a Date-Time Value

HINPUT(source_length, 'source_string', output_length, output)

where:

source_length

Integer

Is the number of characters in the source string to be converted. You can supply the actual value, the name of a numeric field that contains the value, or an expression that returns the value.

source_string

Alphanumeric

Is the string to be converted enclosed in single quotation marks, the name of an alphanumeric field that contains the string, or an expression that returns the string. The string can consist of any valid date-time input value.

output_length

Integer

Is the length of the returned date-time value. Valid values are:

  • 8 indicates a time value that includes one to three decimal digits (milliseconds).
  • 10 indicates a time value that includes four to six decimal digits (microseconds).
  • 12 indicates a time value that includes seven to nine decimal digits (nanoseconds).
output

Date-time

Is the returned date-time value. Is a field that contains the result, or the format of the output value enclosed in single quotation marks. The format must be in date-time format (data type H).

Example: Converting an Alphanumeric String to a Date-Time Value (Reporting)

HCNVRT converts the TRANSDATE field to alphanumeric format, then HINPUT converts the alphanumeric string to a date-time value:

TABLE FILE VIDEOTR2
PRINT CUSTID TRANSDATE AS 'DATE-TIME' AND COMPUTE
ALPHA_DATE_TIME/A20 = HCNVRT(TRANSDATE, '(H17)', 17, 'A20');
DT_FROM_ALPHA/HYYMDS = HINPUT(14, ALPHA_DATE_TIME, 8, 'HYYMDS');
WHERE DATE EQ 2000;
END

The output is:

CUSTID  DATE-TIME         ALPHA_DATE_TIME       DT_FROM_ALPHA
------  ---------         ---------------       -------------
1237    2000/02/05 03:30  20000205033000000     2000/02/05 03:30:00
1118    2000/06/26 05:45  20000626054500000     2000/06/26 05:45:00

Example: Converting an Alphanumeric String to a Date-Time Value (Maintain)

HINPUT converts the DT1 field to alphanumeric format:

MAINTAIN FILE DATETIME
COMPUTE
RESULT/HMtDYYmA = HINPUT(20,'19971029133059888999',10,RESULT);
TYPE RESULT;
END