- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
How to find week of the year of hive column(String)
- Labels:
-
Apache Hive
Created 12-17-2015 10:33 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Created 12-17-2015 12:51 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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;
Created 12-17-2015 12:51 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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;
Created 12-18-2015 05:33 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I guess,from_unixtime function has to convert bigint to "yyyy-MM-dd" not "yyyy-mm-dd".
Created 12-18-2015 10:19 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Suresh Bonam you are right. I updated the answer. Thank you!
