Skip to content
Advertisement

Adding hours to dates in Presto

In a Presto db table, I have two string fields, a date of the form, ‘2022-01-01’, and an hour of the form, 22, for 22:00. I’m trying to combine these two elements into a proper timestamp, with date, hours, minutes, seconds. How can I accomplish this?

What I’ve tried so far

However, I get the error that ‘hour’ is not the proper DATE field. However, from documentation, my arguments appear to the in the proper order. https://prestodb.io/docs/current/functions/datetime.html

Advertisement

Answer

You need to either cast your date to timestamp:

Or parse the string as timestamp:

Output:

_col0
2022-01-01 22:00:00.000
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement