cancel
Showing results for 
Search instead for 
Did you mean: 

calculate the difference of days between two dates in cds view?

former_member231869
Participant
0 Kudos
6,876

Hi,

I want to calculate the difference between the 2 dates .

i have used below function but not working .

Date format : Date1 = 12/05/2020 & Date2 = 12/01/2020

dats_days_between( Date1 , Date2 ) as difference

getting difference in negative random value

Please suggest me is it possible in CDS view?

pfefferf
Active Contributor
0 Kudos

What are the types of the "date" columns you use?

Sandra_Rossi
Active Contributor
0 Kudos

What negative value do you get?

I guess you did it wrong. Why don't you use dats_days_between( Date2 , Date1 )?

For information, ABAP documentation 7.52 of DATS_DAYS_BETWEEN(date1,date2):

  • The function DATS_DAYS_BETWEEN calculates the difference between two specified dates, date1 and date2, in days. The actual parameters must have the predefined data type DATS and should contain a valid date in the format YYYYMMDD. Any invalid dates specified are initialized or set to the value "00010101" before the calculation. The result has the data type INT4. If date2 is greater than date1, the result is positive. In the reverse case, it is negative.
  • Note: Before the difference is calculated, the specified dates are converted to integers, like in ABAP, and the corresponding rules apply.
View Entire Topic
prabhu_04
Explorer
0 Kudos

Hi,

Days should be of type INT4, both negative and positive value for Days is allowed.

If you want Positive Value Date2 is Greater than Date1.