I have a column which has dates in the format mm/dd/yyyy. How do I convert it into yyyy-mm-dd format?
Tried this:- hive> select to_date(from_unixtime(unix_timestamp('02/22/2015', 'yyyy-mm-dd'))); but it doesn't work
In Hive, you are able to choose your preferred date format and calendar layout. To set your date preferences, navigate to your profile dropdown > 'My profile' > 'Edit profile'. 'Date Format' will allow you to change from US (MM/DD/YY) to international format (DD/MM/YY).
2.3 to_date(string timestamp) – Converts Timestamp string to Date type. to_date() function takes timestamp as an input string in the default format yyyy-MM-dd HH:mm:ss and converts into Date type.
from_unixtime: This function converts the number of seconds from unix epoch (1970-01-01 00:00:00 UTC) to a STRING that represents the TIMESTAMP of that moment in the current system time zone in the format of “1970-01-01 00:00:00”. The following example returns the current date including the time.
Hive Date Functions – FAQs If the date value is in default format of 'yyyy-MM-dd' then you can use DATE_FORMAT function to cast a date value to other date format. If the value is in some other format then you can use from_unixtime and unix_timestamp together to cast date to another format.
You can try this:
select from_unixtime(unix_timestamp('02/22/2015' ,'MM/dd/yyyy'), 'yyyy-MM-dd') from table;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With