Hua Cha
Hua Cha

Reputation: 117

Convert YYYY-MM (string) to Date in Hive

Currently, I have a column in a Hive table as YYYY-MM. The data format is string. Instead of string, I want to make it data type as date but still keep it as YYYY-MM. Is that possible? When I make it date data type, it's getting changed to YYYY-MM-DD.

Upvotes: 1

Views: 602

Answers (1)

Vishweshwar
Vishweshwar

Reputation: 56

You can utilize below function for date conversions.

select from_unixtime(unix_timestamp('20100803' ,'yyyyMMdd'), 'yyyy-MM-dd') 

Also, You can have it converted to several formats like you wish to as below. enter image description here

Upvotes: 1

Related Questions