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

Function Module for Date Difference

Former Member
0 Likes
13,237

hi experts ,

i have date_high and number_of_days.

i want to calculate date_low by subtacting number_of_days from date_high.

can anyone please tell me the Fumction Module for the same ?

thanx in advance

akanksha dhanerwal sharma

7 REPLIES 7
Read only

p291102
Active Contributor
0 Likes
2,682

Hi,

SD_DATETIME_DIFFERENCE - This is the function module . In this module we are givng the date and time.

We will get the difference between higher date and lower date and time.

Thanks,

Sankar M

Read only

Former Member
0 Likes
2,682

Hi

Use Below Fm

/SAPHT/DRM_CALC_DATE

Pass No of Days For Days

and Sign must be - Minus..

Hope this helps.

Tahnks

Praveen

Read only

0 Likes
2,682

hi

this FM is not working in BI.

can anyone help?

Read only

Former Member
0 Likes
2,682

hi,

COPF_DETERMINE_DURATION – Calculates difference between date and time

DAYS_BETWEEN_TWO_DATES – Calculates number of days between two dates

FIMA_DAYS_AND_MONTHS_AND_YEARS – Calculates the difference between two dates

HR_HK_DIFF_BT_2_DATES – Days, months and years between two dates

MONTH_PLUS_DETERMINE – Adds or subtracts months to/from a date

RP_CALC_DATE_IN_INTERVAL – Adds/subtracts years, months, days to/from date

SD_DATETIME_DIFFERENCE – Difference in days and time for two dates

SUBTRACT_TIME_FROM_DATE – Subtracts months, days, and years from a given date

Hope this helps.

Read only

Former Member
0 Likes
2,682

Hi,

Use FM:CONVERSION_EXIT_SDATE_OUTPUT.

or FM:CONVERSION_EXIT_IDATE_OUTPUT

or

use below fm: MONTH_NAMES_GET .

data: it_months like t247 occurs 0 with header line.

data: v_text(20).

*date:v_date like sy-datum value '01102007'.

CALL FUNCTION 'MONTH_NAMES_GET'

EXPORTING

LANGUAGE = SY-LANGU

TABLES

MONTH_NAMES = it_months

EXCEPTIONS

MONTH_NAMES_NOT_FOUND = 1

OTHERS = 2

.

IF SY-SUBRC 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

read table it_months with key mnr = sy-datum+4(2).

if sy-subrc = 0.

concatenate sy-datum6(2) '-' it_months-ltx0(3) '-' sy-datum+04) into v_text.

endif.

Read only

Former Member
0 Likes
2,682

Hello Akanksha,

If the Given date is newer than the expected date, try this code:

//PARAMETERS: DATE1 TYPE D,

            DIFF TYPE I.

DATA DATE2 TYPE D.

DATE2 = DATE1 - DIFF.

WRITE:/ 'Expected Date', DATE2.//


Here DATE1 is the Given date and DATE2 is the expected date.


And if you want to get newer and older both dates, try this:


WRITE:/ 'In XPCT field put 0 for future date and put 1 for past dates'.

PARAMETERS: DATE1 TYPE D,

            DIFF TYPE I,

            XPCT TYPE I.

DATA: DATE2 TYPE D,

       DATE3 TYPE D.

DATE2 = DATE1 - DIFF.

DATE3 = DATE1 + DIFF.

IF XPCT = 0.

WRITE:/ 'Expected Date', DATE3.

ELSEIF XPCT = 1.

WRITE:/ 'Expected Date', DATE2.

ENDIF.


Hope this helps.Best of luck.


Regards,

Debayan

Read only

Arun_Prabhu_K
Active Contributor
2,682

Hello Akansha Sharma.

     Your requirement will be met just by simple arithmetic operation.

     DATE_LOW = DATE_HIGH - NUMBER_OF_DAYS.

Regards.