Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Weekday from Date in CDS View using Eclipse

Derive the weekday based on the date.

Sunday = 1

Monday = 2

Tuesday = 3

Wednesday = 4

Thursday = 5

Friday = 6

Saturday = 7

if date is 12/31/2019 i.e Tuesday, output should be '3'

5 REPLIES 5

Sandra_Rossi
Active Contributor
0 Kudos

Something like that (ABAP CDS):

MOD( DATS_DAYS_BETWEEN( CAST( '00010102' AS abap.dats ) , yourdate ) , 7 ) + 1

NB: 0001/01/02 was a Sunday.

bpawanchand
Active Contributor

Hi Tendulkar,

Please check below sample CDS view definition which gives exactly the result what you are expecting

@AbapCatalog.sqlViewName: 'ZV_RND_VIEW'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'A Sample CDS View'
define view ZI_RND_VIEW 
with parameters p_date: abap.dats
as select from I_CalendarDate {
    //I_CalendarDate 
    CalendarDate, 
    CalendarYear, 
    CalendarMonth,  
    WeekDay
} where CalendarDate = $parameters.p_date;

the weekday is the field which gives you the number of the day

Thanks

Pavan Bhamidipati

Hi Pavan,

Will check this code as well. However, the above code mentioned by Sandro is working as expected.

Thanks for your help!

Sandra_Rossi
Active Contributor
0 Kudos

If it's solved, can you tell us how you solved? Thx.

0 Kudos

Hello Sandra,
Greetings.
Sorry for replying late.

I implemented the above code and it worked. Thanks for your help!