Convert two integers into timestamp How do I convert two integers, one for date and one for time, into a timestamp?


Given 20200304 and 1046, return a timestamp for April 3, 2020, 10:46 AM.
Given 20200304 and 946, return a timestamp for April 3, 2020, 9:46 AM.
Given 20200304 and 2359, return a timestamp for April 3, 2020, 11:59 PM.
Given 20200304 and 0, return a timestamp for April 3, 2020, 0:00 AM.


I'm running Version 7, Revision 1.
Try this:

WITH T (YYYYMMDD, HHMM) AS 
(
VALUES
  (20200304, 1046) -- return a timestamp for April 3, 2020, 10:46 AM.
, (20200304,  946) -- return a timestamp for April 3, 2020, 9:46 AM.
, (20200304, 2359) -- return a timestamp for April 3, 2020, 11:59 PM.
, (20200304,    0) -- return a timestamp for April 3, 2020, 0:00 AM.
)
SELECT 
  YYYYMMDD, HHMM
, TIMESTAMP_FORMAT(DIGITS(DEC(YYYYMMDD, 8)) || DIGITS(DEC(HHMM, 4)), 'YYYYMMDDHH24MI') AS TS 
FROM T;


The result is:

|YYYYMMDD   |HHMM       |TS                 |
|-----------|-----------|-------------------|
|20200304   |1046       |2020-03-04 10:46:00|
|20200304   |946        |2020-03-04 09:46:00|
|20200304   |2359       |2020-03-04 23:59:00|
|20200304   |0          |2020-03-04 00:00:00|