Skip to Content
avatar image
Former Member

What will Happen if I add two dates

Hello experts

I tried adding Dates like July 1 + 1 = July 2

but I havent tried adding Dates with different months, Im wondering what will the results be,

example. February 15, 2006 + July 1, 2006

what the result would be?

and what if I tried to add dates woth different year like

March 15, 2004 + December 30 2006, what the outcome shoukd be?

what FM could I used in doing so???

Regards and Thanks,

Christopher

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

5 Answers

  • avatar image
    Former Member
    May 02, 2006 at 02:55 AM

    Hi Christopher,

    I don't think you have FMs for adding date to another date.. You can add months or weeks or days to a particular date..

    Check these FMs..

    ADD_TIME_TO_DATE

    RE_ADD_MONTH_TO_DATE

    BKK_ADD_MONTH_TO_DATE

    Regards,

    SP.

    Add comment
    10|10000 characters needed characters exceeded

  • May 02, 2006 at 02:56 AM

    Hmm interesting!!! Why would anyone want to do that? I have seen requirements where you want to know the number of days between two dates, or find a date which is 'n' number of days plus or minus another given date.

    I haven't come accross this so far. First of all, I would like to see if it makes sense to add two dates. A date like February 15, 2006 is nothing but the number of days since the begining(?). So if you are trying to add two dates, what does it mean. The total number of days since the begining till date 1, plus the total number of days since the begining till date 2? No, I don't think it makes sense to add dates like that.

    Srinivas

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 02, 2006 at 03:41 AM

    HI

    GOOD

    CHECK OUT THIS REPORT,IT MAY HELP YOU TO SOLVE YOUR PROBLEM,

    Data: v_date(8).

    V_date = '20030102'.

    • VAL_DATE <DATE> <FORMAT> <-- Passing Parameters

    val_date v_date 'YYYYMMDD'.

    if sy-subrc = 0.

    write: 'Valid Date' .

    elseif sy-subrc = 1.

    write: 'Invalid Date' .

    elseif sy-subrc = 2.

    write: 'Invalid Date Format' .

    endif.

    ----


    • END OF REPORT *

    ----


    ******************************************************

    • To use the macro "VAL_DATE" GLOBALLY, Insert the *

    • below 2 macros in table TRMAC using Txn SM30. *

    ----


    • Sytax : *

    • VAL_DATA <Date> <Date format>. *

    • It return sy-subrc. *

    • 0 => Valid date - as per the specified format*

    • 1 => Invalid date *

    • 2 => Invalid date format *

    • *

    • <Date format> : *

    • You can pass the following date formats *

    • DDMMYYYY MMDDYYYY YYYYMMDD YYYYDDMM *

    ----


    • Macro VAL-DATE *

    • This macro validate Date according to the specified*

    • format. *

    • Created by Abhishek Kumar *

    • abhi4r@yahoo.com *

    ----


    define val-dat.

    clear: %_date1, %_date2.

    %_date1(4) = &1. "Year

    %_date1+4(2) = &2. "Month

    %_date1+6(2) = &3. "Date

    %_date2 = %_date1 - 1.

    %_date2 = %_date2 + 1.

    if %_date1 <> %_date2.

    sy-subrc = 1.

    else.

    sy-subrc = 0.

    endif.

    end-of-definition.

    ----


    ----


    define val_date.

    data %_date1 like sy-datum.

    data %_date2 like sy-datum.

    data %_date3(8).

    case &2.

    when 'DDMMYYYY'.

    val-date &14(4) &12(2) &1+0(2).

    when 'MMDDYYYY'.

    val-date &14(4) &10(2) &1+2(2).

    when 'YYYYMMDD'.

    val-date &10(4) &14(2) &1+6(2).

    when 'MMYYYYDD'.

    val-date &12(4) &10(2) &1+6(2).

    when others.

    sy-subrc = 2.

    endcase.

    end-of-definition.

    THANKS

    MRUTYUN

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 02, 2006 at 05:26 AM

    Hi Christopher,

    I dont understand the purpose of adding two dates. It would be quite interesting to know your requirement.

    However the answer to your question as to what the result will be, you will get the sum of the years, months and days of the two dates as the result.

    For example

    date type dats value '20051001',

    date1 type dats value '20020510',

    date2 type dats .

    date2 = date1 + date.

    date2 will be 02/09/4007.

    The frequently used function modules with respect to dates are

    MONTH_PLUS_DETERMINE - Determining a new date by adding a number of months

    FIMA_DAYS_AND_MONTHS_AND_YEARS - difference in number of days, months and years between two dates

    ADD_TIME_TO_DATE

    RE_ADD_MONTH_TO_DATE

    BKK_ADD_MONTH_TO_DATE

    RP_LAST_DAY_OF_MONTHS

    HR_E_NUM_OF_DAYS_OF_MONTH

    FIRST_AND_LAST_DAY_IN_YEAR_GET

    DATE_TO_DAY

    DAY_IN_WEEK

    Thanks,

    Susmitha

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 02, 2006 at 05:46 AM

    Hi Christopher,

    I would like to know the purpose of adding two dates!!

    But there are situations where it might be required to find the difference between two dates...(which gives the number of days between the two dates as the result).

    Regards

    Immanuel

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi christopher,

      1. Year does not matter.

      2. when we subtract two dates,

      we just get the difference in number of days.

      3. just copy paste.

      report abc.

      data : diff type i.

      parameters : d1 type sy-datum default '20050101'.

      parameters : d2 type sy-datum default sy-datum.

      start-of-selection.

      diff = d2 - d1.

      write diff.

      regards,

      amit m.