Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

CONCAT two newly created date and time fields in the same query

I have parsed two separate date and time fields from STRINGS to DATES and TIME (see below)

SELECT 
safe.parse_date('%Y%m%d',Arrival_Date) eventdate,
safe.parse_time("%H:%M",Arrival_Time) eventtime
 FROM 
table

Within the same query I now want to CONCAT them into one column as a DATETIME field. I can’t figure it out. CAST(CONCAT doesn’t work as both fields need to safe.parsed due to errors and nulls in the original columns.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You might try below query:

WITH `table` AS (
  SELECT '20221011' Arrival_Date, '10:14' Arrival_Time
)
SELECT safe.parse_date('%Y%m%d',Arrival_Date) eventdate,
       safe.parse_time("%H:%M",Arrival_Time) eventtime,
       safe.parse_datetime("%Y%m%d%H:%M", Arrival_Date || Arrival_Time) eventdatetime,
  FROM `table`;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading