Skip to Content
avatar image
Former Member

difference between two dates

Hi,

how to find the differnce between two dates?(have to get no of days)

date format will be in this format yyyymmdd.

Regards

Ajay

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

10 Answers

  • Best Answer
    avatar image
    Former Member
    May 16, 2008 at 09:22 AM

    FM:HR_HK_DIFF_BT_2_DATES

    Or

    Check this Example..

    DATA:DATE1 TYPE D VALUE '20071220'.

    DATA:DATE2 TYPE D VALUE '20071120'.

    DATA:DAYS TYPE I.

    CALL FUNCTION 'DAYS_BETWEEN_TWO_DATES'

    EXPORTING

    I_DATUM_BIS = DATE1

    I_DATUM_VON = DATE2

    I_KZ_EXCL_VON = '0'

    I_KZ_INCL_BIS = '0'

    I_KZ_ULT_BIS = ' '

    I_KZ_ULT_VON = ' '

    I_STGMETH = '0'

    I_SZBMETH = '1'

    IMPORTING

    E_TAGE = DAYS

    EXCEPTIONS

    DAYS_METHOD_NOT_DEFINED = 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:/ DAYS

    Reward points..

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 16, 2008 at 09:19 AM

    Hi,

    See the following example code.

    **CHANGING DATE FORMAT

    &----


    *& Report ZJE_DATE

    *&

    &----


    *&

    *&

    &----


    REPORT ZJE_DATE.

    data: date(10) type c,

    date1 like date,

    date2 like date.

    date = sy-datum.

    write:/ date.

    write:/ sy-datum.

    write:/ date using edit mask '____:__:__'.

    CALL FUNCTION 'CONVERT_DATE_TO_INTERN_FORMAT'

    EXPORTING

    DATUM = date

    DTYPE = date1

    IMPORTING

    • ERROR =

    IDATE = date2

    • MESSG =

    • MSGLN =

    .

    write:/ date2.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 16, 2008 at 09:24 AM

    hi

    here is function module to find the no days ,no of years,no of months between two dates.

    HR_SGPBS_YRS_MTHS_DAYS

    just check and give me reply

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 16, 2008 at 09:24 AM

    Hi

    You just subtract them

    Exp :

    PARAMETERS: p_date TYPE dats.

    DATA: w_diff TYPE i.

    w_diff = p_date - sy-datum.

    WRITE w_diff.

    Please assign points if helpful.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      CALL FUNCTION 'HR_HK_DIFF_BT_2_DATES'

      EXPORTING

      DATE1 = date1

      DATE2 = date2

      OUTPUT_FORMAT = '02'

      IMPORTING

      • YEARS =

      • MONTHS =

      DAYS = diff

      EXCEPTIONS

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

  • May 16, 2008 at 09:24 AM

    hi use

    HR_HK_DIFF_BT_2_DATES - Calculate the days, months and years between 2

    dates.

    take care date 3 must be greater than date4 for this fm

    parameters : date3 type P0001-BEGDA,

    date4 type P0001-BEGDA.

    data days type P0347-SCRDD.

    caLL FUNCTION 'HR_HK_DIFF_BT_2_DATES'

    EXPORTING

    date1 = date3

    date2 = date4

    OUTPUT_FORMAT = '02'

    IMPORTING

    • YEARS =

    • MONTHS =

    DAYS = days.

    write : days.

    or use

    FIMA_DAYS_AND_MONTHS_AND_YEARS-Get number of days. Year, Months between two dates.

    parameters : date1 type sy-datum,

    date2 type sy-datum.

    data e_days type VTBBEWE-ATAGE.

    CALL FUNCTION 'FIMA_DAYS_AND_MONTHS_AND_YEARS'

    EXPORTING

    i_date_from = date1

    • I_KEY_DAY_FROM =

    i_date_to = date2

    • I_KEY_DAY_TO =

    • I_FLG_SEPARATE = ' '

    IMPORTING

    E_DAYS = e_days

    • E_MONTHS =

    • E_YEARS =

    .

    regards

    prasanth

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 16, 2008 at 09:27 AM

    Hi,

    USe FM /SDF/CMO_DATETIME_DIFFERENCE

    Regards,

    PRashant

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 16, 2008 at 09:30 AM

    Hi,

    Have a look on the following code. It is by using function modules

    data: num type c.

    CALL FUNCTION 'DAYS_BETWEEN_TWO_DATES'

    EXPORTING

    i_datum_bis = '20080516'

    i_datum_von = '20080510'

    IMPORTING

    E_TAGE = num

    EXCEPTIONS

    DAYS_METHOD_NOT_DEFINED = 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:/ num.

    Reward,if useful.

    Thanks,

    Chandu

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 16, 2008 at 09:30 AM

    Hi,

    use this function module,

    CALL FUNCTION 'HR_SGPBS_YRS_MTHS_DAYS'

    EXPORTING

    beg_da = s_date-low

    end_da = s_date-high

    IMPORTING

    no_cal_day = d.

    Regards,

    kk.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 16, 2008 at 09:33 AM

    Hi,

    1. Please search the forum, this question is asked almost every day.

    2. There are a number of function modules that will do this, but by far the easiest is to subtract one date field from the other. The result is the number of days.

    DATA: W_DATE1 TYPE DATS,
               W_DATE2 TYPE DATS.
    
    DATA: RESULT(4) TYPE C.
    
    RESULT = W_DATE1 - W_DATE2.
    

    Regards,

    Nick

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 16, 2008 at 09:38 AM

    Hi,

    See below eg:

    data: d1(8) type n,

    d2(8) type n,

    r type n.

    d1 = '20080501'.

    d2 = '20080510'.

    r = d2 - d1.

    write: r.

    I got the result 9.

    Regards

    Ganesh

    Add comment
    10|10000 characters needed characters exceeded