Skip to Content
0

To Derive Saturday date based on a date field in SAP HANA SQL

Aug 08, 2017 at 12:54 PM

45

avatar image
Former Member

Hello All,

I need to derive the Saturday date based on a Date range field in my Procedure. Please help me with the code

For e.g. If the date range is from a Wednesday (Aug 9th, 2017) to Sunday(Aug 13th, 2017), i need to get the date value as August 12th, 2017 which is a Saturday.

SQL
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

avatar image
Former Member Aug 09, 2017 at 06:23 AM
-2

I need logic to get range of date and derive the saturday in the date range.

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

I didn't get, what you are looking for. One of the above 2 solutions should solve your problem.

0
avatar image
Former Member Aug 08, 2017 at 06:09 PM
0
create column table dates(date_col	date)


insert into dates values ('20170808');
insert into dates values ('20170809');
insert into dates values ('20170810');
insert into dates values ('20170811');
insert into dates values ('20170812');
insert into dates values ('20170813');
insert into dates values ('20170814');
insert into dates values ('20170815');
insert into dates values ('20170816');


select * from dates where dayname(date_col) = 'SATURDAY';
Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi. Thanks for your response. But my date value is not constant. it will be dynamic.

0
avatar image
Former Member Aug 08, 2017 at 06:25 PM
0

Hi Sneha,

you can query M_TIME_DIMENSION with DAY_OF_WEEK = '05' to get Saturdays. For

hope this helps.

Prasad A V


Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi. Thanks for your response. But my date value is not constant. it will be dynamic.

0
avatar image
Former Member Aug 10, 2017 at 06:23 AM
0

Hi All,

thanks i didnt want data for any specific values. the date field based on which i need to calculate the Saturday is changing value.

Anyways, i got the solution for the same.

In the graphical week itself, i created a calculated column to determine the week-number & based on the week-number, we can add/subtract days to get the Saturday date for that particular week (created a calculated column with nested IF condition)

Hope this helps in case you come across this kind of issue in future.

Share
10 |10000 characters needed characters left characters exceeded