Skip to main content
APentyala
Silver ⭐️⭐️
Jan 26, 2025 2:41 PM UTC
Solved

Sting to Timestamp (6) in Hive

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

 

 

ggangadharan
Gold ⭐️
Feb 4, 2025 2:33 PM UTC

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);





2 replies

APentyala
APentyalaAuthor
Silver ⭐️⭐️
Feb 4, 2025 7:44 AM UTC

Any inputs?

Translate
apentyala
ggangadharan
Gold ⭐️
Gold ⭐️
Feb 4, 2025 2:33 PM UTC

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);





Translate