Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

How to find week of the year of hive column(String)

Solved Go to solution

How to find week of the year of hive column(String)

Rising Star

Hi everyone, In my hive table i have values in one column are like " Thu Dec 17 15:55:08 IST 2015 " .For this particular column i would like to find "week of the year".How can i do that one .Assume column name is survey_date and data type is string.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: How to find week of the year of hive column(String)

@Suresh Bonam

Try this:

select weekofyear(from_unixtime(unix_timestamp('Thu Dec 17 15:55:08 IST 2015', 'EEE MMM d HH:mm:ss Z yyyy'),'yyyy-MM-dd')) from sample_07 limit 1;


select weekofyear(from_unixtime(unix_timestamp('Thu Dec 02 15:55:08 IST 2015', 'EEE MMM d HH:mm:ss Z yyyy'),'yyyy-MM-dd')) from sample_07 limit 1;

View solution in original post

3 REPLIES 3
Highlighted

Re: How to find week of the year of hive column(String)

@Suresh Bonam

Try this:

select weekofyear(from_unixtime(unix_timestamp('Thu Dec 17 15:55:08 IST 2015', 'EEE MMM d HH:mm:ss Z yyyy'),'yyyy-MM-dd')) from sample_07 limit 1;


select weekofyear(from_unixtime(unix_timestamp('Thu Dec 02 15:55:08 IST 2015', 'EEE MMM d HH:mm:ss Z yyyy'),'yyyy-MM-dd')) from sample_07 limit 1;

View solution in original post

Highlighted

Re: How to find week of the year of hive column(String)

Rising Star

I guess,from_unixtime function has to convert bigint to "yyyy-MM-dd" not "yyyy-mm-dd".

Highlighted

Re: How to find week of the year of hive column(String)

@Suresh Bonam you are right. I updated the answer. Thank you!

Don't have an account?
Coming from Hortonworks? Activate your account here