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: 

Released FM to calculate days between dates ?

0 Kudos

To calculate days between two days I have used a FM.T urns out its not released Function module and so not acceptable (learned this in code review).I searched every possible FM ,but none is released. Can anyone suggest any FM that could be used to calculate days between two dates or should I write the code myself?

1 ACCEPTED SOLUTION

jmodaal
Active Contributor

Hello,

hmm, actually the need for a function module is not clear to me. Using the right type you can subtract a date from another to get the days between them.

data: date1 type syst-datum value '20220217',
date2 type syst-datum value '20220315'.
"...
data(diffDays) = date1 - date2.
write:/ diffDays.
7 REPLIES 7

jmodaal
Active Contributor

Hello,

hmm, actually the need for a function module is not clear to me. Using the right type you can subtract a date from another to get the days between them.

data: date1 type syst-datum value '20220217',
date2 type syst-datum value '20220315'.
"...
data(diffDays) = date1 - date2.
write:/ diffDays.

DominikTylczyn
Active Contributor

Hello kee1212

To supplement jmodaal perfect response - if you need to work with working dates and factory calendars, you can use the official Calendar Functions

Best regards

Dominik Tylczynski

former_member9115
Participant
0 Kudos

Hi,

Try Function :- HR_HK_DIFF_BT_2_DATES

CALL FUNCTION 'HR_HK_DIFF_BT_2_DATES' "--Difference between two Dates

EXPORTING
  DATE1 = SY-DATUM
  DATE2 = MATDOC-BUDAT
  OUTPUT_FORMAT = '02'
IMPORTING
  "YEARS =
  "MONTHS =
  DAYS = DAY_CNT
EXCEPTIONS
 OVERFLOW_LONG_YEARS_BETWEEN = 1
 INVALID_DATES_SPECIFIED = 2
 OTHERS = 3.

IF SY-SUBRC <> 0.
" Implement suitable error handling here
ENDIF.

0 Kudos

HR_HK_DIFF_BT_2_DATES is not released for customer's usage. That's the primary issue raised in by the OP. If they use HR_HK_DIFF_BT_2_DATES, they will not pass the code review again.

0 Kudos

Yes, you are correct. Thanks.

Sandra_Rossi
Active Contributor
0 Kudos

Do you want to exclude the days off (like Sunday) or to count all the days between 2 dates?

Sandra_Rossi
Active Contributor
0 Kudos

You may search the forum/SAP Web site with your favorite Web search engine. I see many answers for search below. Based on the results, if it still doesn't solve, you may anyway refine your investigations and provide more information here.

Released FM to calculate days between dates site:sap.com

You don't get so many answers, and you can check which code is released or not. If you don't know, search again:

Which function modules are released site:sap.com