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: 

need to calculate months between two dates in CDS view.

0 Kudos

Hi experts,

I have two dates based on their differences I need to calculate months from them.

Previously in ECC we were using FM: 'FIMA_DAYS_AND_MONTH_AND_YEARS to calculate months. I search many SDN blogs, but I can't find any solution on this.

Can this is possible in CDS view to calculates months directly, like we use to calculate date difference using

Function DATS_DAYS_BETWEEN or any other suggestion to achieve this logic in Hana?

Thanks,

Mahendra

Information added by Moderator: An ABAP CDS view is implemented, not a HANA CDS View.

6 REPLIES 6

0 Kudos

Can you please tell me how I will use function DAYS_BETWEEN in existing CDS joining Query?

I am using this way,

DAYS_BETWEEN(audat, vdatu) as no_of_days

but getting syntax error that function days_between is unknown.

pfefferf
Active Contributor
0 Kudos

What HANA version you are using?

You are sure that you are using HANA CDS views and not ABAP CDS views?

Can you show your whole CDS View syntax?

0 Kudos

Hana version- 2.00.031 (SP03)

maheshpalavalli
Active Contributor

Hi gaurav mahendra,

You have another function availbe in CDS:

DATS_DAYS_BETWEEN(date1,date2) @Florian Pfeffer thanks, i didn't see that it is available. Just checked 🙂

Ignore below:

****If you are using ABAP CDS****

You need to use the combination of AMDP, Table function & CDS view to achieve this. Check the answer and the mentioned blog below, instead of date to day and month you need to use days between function in the AMDP

https://answers.sap.com/questions/704604/cds-date-to-daymonth.html?childToView=703560#answer-703560

BR,
Mahesh

pfefferf
Active Contributor
0 Kudos

When you get that error, than it seems that you are not using a HANA CDS View, but an ABAP CDS View.

What NetWeaver version are you using (as you mentioned function DATS_DAYS_BETWEEN in your question and is not available I think, otherwise you would have used it)?

loyd_enochs3
Participant
0 Kudos

The function module FIMA_DAYS_AND_MONTHS_AND_YEARS is not released to customer use, which may explain the lack of SDN blog entries.

I may be underestimating the complexity of your task but have you considered simply subtracting the month values from each other? In the example code, the Parameters would be substituted with the specific fields you are working with, of course.

PARAMETERS: p_from TYPE sy-datum DEFAULT sy-datum,
            p_to   TYPE sy-datum.
DATA: answer TYPE numc04.

START-OF-SELECTION.
  answer = p_to+4(2) - p_from+4(2).
  WRITE answer.