Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Archives of Support Questions (Read Only)

This is an archived board for historical reference. Information and links may no longer be available or relevant
Announcements
This board is archived and read-only for historical reference. To ask a new question, please post a new topic on the appropriate active board.

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

avatar
Rising Star

1 ACCEPTED SOLUTION

avatar
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

avatar
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

avatar

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