02-17-2022 9:02 AM
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?
02-17-2022 9:09 AM
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.
02-17-2022 9:09 AM
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.
02-17-2022 9:33 AM
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
02-17-2022 11:31 AM
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.
02-17-2022 12:30 PM
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.
02-18-2022 4:31 AM
02-17-2022 4:19 PM
Do you want to exclude the days off (like Sunday) or to count all the days between 2 dates?
02-17-2022 4:21 PM
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