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: 

Function module to find the months between two different dates

Former Member
0 Kudos

Hi,

I have a requirement in which the client wants to change the product from existing one to new product(report)....and i have to check whether the client is changing the product before 12 months of the issue date of existing product.

How do i do this..is ther any function module to find the month between two different dates??

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

Check the following code:

REPORT ZDATEDIFF.

DATA: EDAYS LIKE VTBBEWE-ATAGE,

EMONTHS LIKE VTBBEWE-ATAGE,

EYEARS LIKE VTBBEWE-ATAGE.

PARAMETERS: FROMDATE LIKE VTBBEWE-DBERVON,

TODATE LIKE VTBBEWE-DBERBIS DEFAULT SY-DATUM.

call function 'FIMA_DAYS_AND_MONTHS_AND_YEARS'

exporting

i_date_from = FROMDATE

i_date_to = TODATE

  • I_FLG_SEPARATE = ' '

IMPORTING

E_DAYS = EDAYS

E_MONTHS = EMONTHS

E_YEARS = EYEARS.

WRITE:/ 'Difference in Days ', EDAYS.

WRITE:/ 'Difference in Months ', EMONTHS.

WRITE:/ 'Difference in Years ', EYEARS.

INITIALIZATION.

FROMDATE = SY-DATUM - 60.

Regards,

Bhaskar

5 REPLIES 5

Former Member
0 Kudos

Hi,

Check the following code:

REPORT ZDATEDIFF.

DATA: EDAYS LIKE VTBBEWE-ATAGE,

EMONTHS LIKE VTBBEWE-ATAGE,

EYEARS LIKE VTBBEWE-ATAGE.

PARAMETERS: FROMDATE LIKE VTBBEWE-DBERVON,

TODATE LIKE VTBBEWE-DBERBIS DEFAULT SY-DATUM.

call function 'FIMA_DAYS_AND_MONTHS_AND_YEARS'

exporting

i_date_from = FROMDATE

i_date_to = TODATE

  • I_FLG_SEPARATE = ' '

IMPORTING

E_DAYS = EDAYS

E_MONTHS = EMONTHS

E_YEARS = EYEARS.

WRITE:/ 'Difference in Days ', EDAYS.

WRITE:/ 'Difference in Months ', EMONTHS.

WRITE:/ 'Difference in Years ', EYEARS.

INITIALIZATION.

FROMDATE = SY-DATUM - 60.

Regards,

Bhaskar

Former Member
0 Kudos

Check this FM MONTHS_BETWEEN_TWO_DATES

Former Member
0 Kudos

FM: HR_AUPBS_MONTH_DAY

This FM will return you number of Years, Months and Days between Begin date and endDate.

Former Member
0 Kudos

Hi Sudheer,

Have a look at the following link.

http://abapcode.blogspot.com/2008/01/sap-function-module-for-date-and-time.html

Regards,

Kinshuk

Former Member
0 Kudos

Hi,

Use the FM, 'HR_HK_DIFF_BT_2_DATES' to find the number of months exists between the given 2 dates.

See the following example...

Data: d1 type sy-datum,

d2 type sy-datum,

wf_month_diff type P0347-SCRMM.

call function 'HR_HK_DIFF_BT_2_DATES'

exporting

date1 = d1

date2 = d2

output_format = '04'

importing

months = wf_month_diff.

  • In the 'wf_month_diff' variable, you will get the month difference between these two dates.

Regards,

Shanthi.P

            • Reward points if useful *****