Support Questions

Find answers, ask questions, and share your expertise

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

avatar
Expert Contributor

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

avatar

@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

avatar

@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;

avatar
Expert Contributor

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

avatar

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