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 - Difference between dates in months

Former Member
0 Likes
1,065

Hello ,

I want to check condition on the basis of difference between two dates .

One date is current date .

Second date - From table

Please help me with Fm which will give difference between two dates in Months .

Thanks and Regards ,

Rahul

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
995

Hi,

Use the below logic.

data: v_days type i,

v_months type i,

v_years type i,

v_all_days type i.

CALL FUNCTION 'HR_SGPBS_YRS_MTHS_DAYS'

EXPORTING

BEG_DA = '20080101'

END_DA = '20080416'

IMPORTING

NO_DAY = v_days

NO_MONTH = v_months

NO_YEAR = v_years

NO_CAL_DAY = v_all_days.

write:/ 'Days = ', v_days.

write:/ 'Months = ', v_months.

write:/ 'Years = ', v_years.

write:/ 'All days = ', v_all_days.

7 REPLIES 7
Read only

Former Member
0 Likes
995

Hi,

Please use FMs below:


DAYS_BETWEEN_TWO_DATES  "Gives difference in days
MONTHS_BETWEEN_TWO_DATES " Gives difference in months

Thanks,

Sriram Ponna.

Read only

Former Member
0 Likes
995

Use :FM HR_HK_DIFF_BT_2_DATES

pass 04 for parameter OUTPUT_FORMAT

Read only

Former Member
0 Likes
995

Hello

You may want to try FM DAYS_BETWEEN_TWO_DATES or use se37 to find other FMs that do date calculations.

Regards

Greg Kern

Read only

Former Member
0 Likes
996

Hi,

Use the below logic.

data: v_days type i,

v_months type i,

v_years type i,

v_all_days type i.

CALL FUNCTION 'HR_SGPBS_YRS_MTHS_DAYS'

EXPORTING

BEG_DA = '20080101'

END_DA = '20080416'

IMPORTING

NO_DAY = v_days

NO_MONTH = v_months

NO_YEAR = v_years

NO_CAL_DAY = v_all_days.

write:/ 'Days = ', v_days.

write:/ 'Months = ', v_months.

write:/ 'Years = ', v_years.

write:/ 'All days = ', v_all_days.

Read only

0 Likes
995

Hello ,

Thanks for the response .

Have a nice day ahead .

Thanks and regards ,

RRAI

Read only

Former Member
0 Likes
995

Hi,

You can use the below function modules.

HR_ECM_GET_NUMBER_OF_MONTHS

HR_GBSXP_GET_MONTHS

HR_IN_CALC_MONTHS

Read only

Former Member
0 Likes
995

Hi,

Check the below code.

data: v_months type i.

CALL FUNCTION 'HR_GBSXP_GET_MONTHS'

EXPORTING

FIRST_DATE = '20080101'

SECOND_DATE = '20080416'

MODIFY_INTERVAL = 'M'

IMPORTING

DURATION = v_months

EXCEPTIONS

INVALID_SEQ_DATES = 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.

write:/ v_months.