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.

hive query to display Week of the timestamp and its start Date and End Date.

Solved Go to solution
Highlighted

hive query to display Week of the timestamp and its start Date and End Date.

1 ACCEPTED SOLUTION

Accepted Solutions

Re: hive query to display Week of the timestamp and its start Date and End Date.

select weekofyear(current_timestamp)

Above query would give you the week of the timestamp.

To get the first day of the week -->

select date_sub(current_timestamp,pmod(datediff(current_timestamp,'1900-01-07'),7));

To get last day of the week -->

select last_day(current_timestamp);

Hope it helps @Gayathri Devi

View solution in original post

2 REPLIES 2

Re: hive query to display Week of the timestamp and its start Date and End Date.

select weekofyear(current_timestamp)

Above query would give you the week of the timestamp.

To get the first day of the week -->

select date_sub(current_timestamp,pmod(datediff(current_timestamp,'1900-01-07'),7));

To get last day of the week -->

select last_day(current_timestamp);

Hope it helps @Gayathri Devi

View solution in original post

Highlighted

Re: hive query to display Week of the timestamp and its start Date and End Date.

@Gayathri Devi

I couldn't think of any built in function in hive to handle this scenario.

The other way of doing this is by using something like below:

select from_unixtime(unix_timestamp(current_timestamp)+7200);

7200 implies seconds needed for 2 hours as mentioned in your quetion. You can alter it based on your need.

Instead of the hardcoded value you can pass variable or row_number()over() * 3600 can be used to generate sequentially.

Hope it Helps!!

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