Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert mm/dd/yyyy to yyyy-mm-dd in Hive

Tags:

hadoop

hive

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

like image 655
TrialAndError Avatar asked Jan 28 '16 05:01

TrialAndError


People also ask

How do I change the date format in Hive?

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

How do I convert Yyyymmdd to date in Hive?

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.

What is from_unixtime in Hive?

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.

How do I get the month and year from a date in Hive?

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.


1 Answers

You can try this:

select from_unixtime(unix_timestamp('02/22/2015' ,'MM/dd/yyyy'), 'yyyy-MM-dd') from table;
like image 99
Rahul Tripathi Avatar answered Sep 28 '22 12:09

Rahul Tripathi