Skip to Content
avatar image
Former Member

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

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

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.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 08, 2017 at 06:09 PM
    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';
    
    Add comment
    10|10000 characters needed characters exceeded

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

    Hi Sneha,

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

    hope this helps.

    Prasad A V

    Add comment
    10|10000 characters needed characters exceeded

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

    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.

    Add comment
    10|10000 characters needed characters exceeded