Skip to Content
author's profile photo Former Member
Former Member

how to calculate the number of months....

HI all

can any body give the FM name which calculates the number of months between any two dates that are inputted

thanks in advance

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

9 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Mar 20, 2008 at 09:10 AM

    hi use this..

    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,

    venkat.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 20, 2008 at 09:10 AM

    SD_DATETIME_DIFFERENCE

    reward if useful

    S@meer

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 20, 2008 at 09:11 AM

    USE :

    MONTHS_BETWEEN_TWO_DATES

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 20, 2008 at 09:11 AM

    Hi,

    Use the FM MONTHS_BETWEEN_TWO_DATES

    Reward points if useful.

    Regards,

    Sowmya.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 20, 2008 at 09:11 AM

    Hi

    Try this

    MONTHS_BETWEEN_TWO_DATES

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 20, 2008 at 09:15 AM

    Try this in ur source code of FM.....include the import and Export...as given

    *"----


    ""Local interface:

    *" IMPORTING

    *" REFERENCE(BEGDA) LIKE PA0001-BEGDA

    *" REFERENCE(ENDDA) LIKE PA0001-ENDDA

    *" EXPORTING

    *" REFERENCE(DIFF_MONTHS) TYPE I

    *" EXCEPTIONS

    *" ENDDA_GRTR

    *"----


    DATA : SMONTH TYPE I,

    EMONTH TYPE I,

    SDATE TYPE I,

    EDATE TYPE I,

    SYEAR TYPE I,

    EYEAR TYPE I,

    MONTHSTOBEADDED TYPE I,

    YRDIFF TYPE I,

    DIFF TYPE I.

    • Calculating the months to be added

    SMONTH = BEGDA+4(2).

    EMONTH = ENDDA+4(2).

    • Finding the difference in years

    SYEAR = BEGDA+0(4).

    EYEAR = ENDDA+0(4).

    IF SYEAR <> EYEAR .

    SYEAR = SYEAR + 1.

    DIFF = ( 12 - SMONTH ) + 1.

    YRDIFF = EYEAR - SYEAR.

    IF YRDIFF > 0 .

    DIFF = DIFF + ( YRDIFF * 12 ).

    ENDIF.

    DIFF = DIFF + EMONTH.

    ELSE.

    DIFF = ( EMONTH - SMONTH ) + 1.

    ENDIF.

    DIFF_MONTHS = DIFF.

    ENDFUNCTION.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 20, 2008 at 09:15 AM

    DATA : w_months TYPE i.

    u can give dates using variable also...i have hardcoded just for example...

    CALL FUNCTION 'FIMA_DAYS_AND_MONTHS_AND_YEARS'

    EXPORTING

    i_date_from = '20070101'

    i_date_to = '20070205'

    IMPORTING

    e_months = w_months

    .

    WRITE : w_months.

    rewards points if useful..

    Sachin

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 20, 2008 at 09:17 AM

    Thaks for giving some quick answers

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 20, 2008 at 09:17 AM

    Thanks for giving some quick answers

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.