Application Development and Automation 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: 
Read only

Get Weekday from Date in CDS View using Eclipse

Former Member
6,420

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'

Hello Sandra,
Greetings.
Sorry for replying late.

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

5 REPLIES 5
Read only

Sandra_Rossi
Active Contributor
5,132

Something like that (ABAP CDS):

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

NB: 0001/01/02 was a Sunday.

Read only

bpawanchand
Active Contributor
5,132

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

Read only

5,132

Hi Pavan,

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

Thanks for your help!

Read only

Sandra_Rossi
Active Contributor
0 Likes
5,132

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

Read only

Former Member
0 Likes
5,132

Hello Sandra,
Greetings.
Sorry for replying late.

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