Reputation: 63
Could you please guide with below query. I need to convert below string column to date.
Input and expected output is provided in screenshot.
Input table: column maturity_date is in string datatype.
I tried below but not working as expected
to_date(from_unixtime(unix_timestamp(maturity_date,'MM/DD/YYYY H:mm:ss'),'yyyy-mm-dd')
Upvotes: 1
Views: 529
Reputation: 42332
Try using lower case letters. Upper case means another thing (day of year (D) and week-year (Y)).
to_date(from_unixtime(unix_timestamp(maturity_date,'MM/dd/yyyy H:mm:ss'),'yyyy-MM-dd')
Upvotes: 1
Reputation: 38290
Correct input format is 'MM/dd/yyyy H:mm:ss'
, not 'MM/DD/YYYY H:mm:ss'
Correct output format is yyyy-MM-dd
, not yyyy-mm-dd.
mm is minutes. MM
is month
Read more about date format used in Hive here SimpleDateFormat
Upvotes: 1