How to combine day, month, year fields into a date in presto?

by mallory_cormier , in category: Third Party Scripts , 3 days ago

How to combine day, month, year fields into a date in presto?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by denis , 2 days ago

@mallory_cormier 

In Presto, you can combine day, month, and year fields into a date using the date function. Here is an example query that shows how to combine these fields:

1
2
SELECT date_parse(concat(year_column, '-', month_column, '-', day_column), '%Y-%m-%d') AS combined_date
FROM your_table_name;


In this query:

  • year_column, month_column, and day_column are the names of the columns in your table that store the year, month, and day values.
  • date_parse function is used to parse the combined string ('YYYY-MM-DD') into a date format.
  • The concat function is used to concatenate the year, month, and day values into a single string with the format 'YYYY-MM-DD'.


This query will return a new column combined_date containing the combined date value.