HTIME: Converting the Time Portion of a Date-Time Value to a Number

How to:

Available Languages: reporting, Maintain

The HTIME function converts the time portion of a date-time value to the number of milliseconds if the length argument is eight, microseconds if the length argument is ten, or nanoseconds if the length argument is 12.

Syntax: How to Convert the Time Portion of a Date-Time Value to a Number

HTIME(length, datetime, output)

where:

length

Integer

Is the length of the input 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).
datetime

Date-time

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

output

Floating-point double-precision

Is the field that contains the result, or the format of the output value enclosed in single quotation marks. The format must be floating-point double-precision.

Example: Converting the Time Portion of a Date-Time Field to a Number (Reporting)

HTIME converts the time portion of the TRANSDATE field to the number of milliseconds:

TABLE FILE VIDEOTR2
PRINT CUSTID TRANSDATE AS 'DATE-TIME' AND COMPUTE
MILLISEC/D12.2 = HTIME(8, TRANSDATE, 'D12.2');
WHERE DATE EQ 2000;
END

The output is:

CUSTID  DATE-TIME               MILLISEC
------  ---------               --------
1237    2000/02/05 03:30   12,600,000.00
1118    2000/06/26 05:45   20,700,000.00

Example: Converting the Time Portion of a Date-Time Field to a Number (Maintain)

HTIME converts the time portion of the DT1 field to the number of milliseconds:

MAINTAIN FILE DATETIME
FOR 1 NEXT ID INTO STK;
COMPUTE MILLISEC/D12.2 = HTIME(8, STK.DT1, MILLISEC);
TYPE "STK(1).DT1 = <STK(1).DT1";
TYPE "MILLISEC = <MILLISEC";
END