Reputation: 12983
Entries in my table are saved with a date, as distinct fields day
, month
and year
. I want to read the dates as Date type.
What's the correct way to do it?
Upvotes: 3
Views: 5295
Reputation: 1305
Another way:
date(format('%d-%d-%d', 2020, 3, 31))
Based on Calculate date and weekending date on Presto
Upvotes: 5
Reputation: 1637
You can use date_parse function.
SELECT date(date_parse('2020' || '04' || '08', '%Y%m%d'))
SELECT date(date_parse(CAST(year as VARCHAR) || '-' || CAST(month as VARCHAR) || '-' || CAST(day as VARCHAR), '%Y-%c-%e'))
You may need to edit the format based on your data. https://prestosql.io/docs/0.172/functions/datetime.html#mysql-date-functions
Upvotes: 3