Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Support Questions

Find answers, ask questions, and share your expertise
Announcements
Share your experience with Cloudera on G2 and get a $25 Amazon Gift card.
Hi, I'm CLEO! Something exciting is coming to the Community. Stay Tuned!

Sting to Timestamp (6) in Hive

avatar
Explorer

Hi Team,

I’m seeking your support in converting a string to a timestamp with microseconds in Hive. When using unixtimestamp, I notice that the milliseconds are being dropped. Could you please advise on how to capture milliseconds (and microseconds) correctly, and which data type I should use to store the value in Hive?

SELECT from_unixtime(unix_timestamp('2024-11-05-10.03.17.872195', 'yyyy-MM-dd-HH.mm.ss.SSSSSS')) as times,'2024-11-05-10.03.17.872195' as vale
FROM

APentyala_0-1737902409390.png

 

 

apentyala
1 ACCEPTED SOLUTION

avatar
Master Collaborator

Use CAST to convert to TIMESTAMP type. 

SELECT CAST('2024-11-05 10:03:17.872195' AS TIMESTAMP) AS timestamp_value;

We can also try TIMESTAMP WITH LOCAL TIME ZONE, This helps retain precision when dealing with timezones.

SELECT CAST('2024-11-05 10:03:17.872195' AS TIMESTAMP WITH LOCAL TIME ZONE);





View solution in original post

2 REPLIES 2

avatar
Explorer

Any inputs?

apentyala

avatar
Master Collaborator

Use CAST to convert to TIMESTAMP type. 

SELECT CAST('2024-11-05 10:03:17.872195' AS TIMESTAMP) AS timestamp_value;

We can also try TIMESTAMP WITH LOCAL TIME ZONE, This helps retain precision when dealing with timezones.

SELECT CAST('2024-11-05 10:03:17.872195' AS TIMESTAMP WITH LOCAL TIME ZONE);