01-24-2023 08:33 PM
I have a field stored as a string in the format "12/30/2022 10:30:00 AM"
What is the easiest way to convert the string into a timestamp, with the timezone of my choosing?
01-24-2023 10:42 PM
01-29-2023 11:06 PM
I don't seem to be getting the same result... note no timezone info in my results;
Is there a config setting I'm missing or something?
01-30-2023 04:57 PM
Just to answer my own question, in case anyone else googles for this...
FirstIy, don't know why timezone isn't displaying in my query results using a SQL Warehouse, but it works ok using a compute cluster, so I'm guessing it is a display issue rather than a data issue.
Secondly, from what I can tell, using the TO_TIMESTAMP function will apply the timezone for your session (which might not be the timezone you want). I didn't realise this could be solved pretty easily by simply pasting your timezone to the end of the date string, like this;
TO_TIMESTAMP(MyDateTimeString || ' Timezone', 'M/d/y h:m:s a z)
For example;
TO_TIMESTAMP(MyDateTimeString || ' America/Los_Angeles', 'M/d/y h:m:s a z)
02-04-2023 06:30 AM
Use to_utc_timestamp(expr,timezone)
01-25-2023 04:07 AM
yesterday
TO_DATE("12/30/2022 10:30:00 AM", "MM/dd/yyyy HH:mm:ss a") AS tsDate
Is this correct if we need only date?
02-03-2023 03:48 AM
use from_utc_timestamp(to_timestam("<string>", <format>),<timezone>)
Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.
If there isn’t a group near you, start one and help create a community that brings people together.
Request a New Group