HTMTOTS or TIMETOTS: Converting a Time to a Timestamp

How to:

The HTMTOTS function returns a timestamp using the current date to supply the date components of its value, and copies the time components from its input date-time value.

Note: TIMETOTS is a synonym for HTMTOTS.

Syntax: How to Convert a Time to a Timestamp

HTMTOTS(time, length, output)

or

TIMETOTS(time, length, output)

where:

time

Date-Time

Is the date-time value whose time will be used. The date portion will be ignored.

length

Integer

Is the length of the result. This can be one of the following:

  • 8 for input time values including milliseconds.
  • 10 for input time values including microseconds.
  • 12 for input time values including nanoseconds.
output_format

Date-Time

Is the timestamp whose date is set to the current date, and whose time is copied from time.

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

Example: Converting a Time to a Timestamp

HTMTOTS converts the time portion of the TRANSDATE field to a timestamp, using the current date for the date portion of the returned value:

DEFINE FILE VIDEOTR2
  TSTMPSEC/HYYMDS = HTMTOTS(TRANSDATE, 8, 'HYYMDS');
END 
TABLE FILE VIDEOTR2
PRINT TRANSDATE TSTMPSEC
BY LASTNAME BY FIRSTNAME
WHERE DATE EQ '1991'
END

The output is:

LASTNAME         FIRSTNAME   TRANSDATE         TSTMPSEC
--------         ---------   ---------         --------
CRUZ             IVY         1991/06/27 02:45  2011/01/11 02:45:00
GOODMAN          JOHN        1991/06/25 01:19  2011/01/11 01:19:00
GREEVEN          GEORGIA     1991/06/24 10:27  2011/01/11 10:27:00
HANDLER          EVAN        1991/06/20 05:15  2011/01/11 05:15:00
                             1991/06/21 07:11  2011/01/11 07:11:00
KRAMER           CHERYL      1991/06/21 01:10  2011/01/11 01:10:00
                             1991/06/19 07:18  2011/01/11 07:18:00
                             1991/06/19 04:11  2011/01/11 04:11:00
MONROE           CATHERINE   1991/06/25 01:17  2011/01/11 01:17:00
                 PATRICK     1991/06/27 01:17  2011/01/11 01:17:00
SPIVEY           TOM         1991/11/17 11:28  2011/01/11 11:28:00
WILLIAMS         KENNETH     1991/06/24 04:43  2011/01/11 04:43:00
                             1991/06/24 02:08  2011/01/11 02:08:00