Home > Software engineering >  CONCAT two newly created date and time fields in the same query
CONCAT two newly created date and time fields in the same query

Time:10-11

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.

CodePudding user response:

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`;
  • Related