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

Problem with the Date

HI frendz,

I have to retrieve data considering the date range.I have to check a date in the where condition which should within the last 12 months.So my one interval will be sydatum but how can i get the other interval ie 1 year back date ?? Is there any std function module which gives one year back date if we give the present date. Pls help me out in this ASAP...

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Posted on Jul 22, 2005 at 06:12 AM

    Hi,

    Use date_in_future . Give the date in Import_datum parameter and give -365 in anzahl_tage .You can see the output.But for leap year , you need to take care.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 22, 2005 at 06:21 AM

    hi,

    try that:

    yr_back_date = sy-datum .

    SUBTRACT 1 FROM yr_back_date+3(1).

    regards Andreas

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 22, 2005 at 06:57 AM

    hi

    try this

    CALL FUNCTION 'BKK_ADD_MONTH_TO_DATE'

    EXPORTING

    months = -12

    olddate = sy-datum

    IMPORTING

    NEWDATE = dt_new

    .

    dt_new gives u a 12 month previous date

    check out my reply in this post for some more function modules...

    https://www.sdn.sap.com/sdn/collaboration.sdn?node=linkFnode6-1&contenttype=url&content=https://function-module-to-count-periods-elapsed

    regards,

    PJ

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 22, 2005 at 07:03 AM

    Hi Nagarjuna,

    In general, when we say the data one year back, we take the date one day after the current date and one year before the current year -

    For example - If today is 22nd July 2005, one year back, the date should be taken as 23rd july 2004.

    Look at the following snippet of code -

    PARAMETERS : PRESENT TYPE D.
    
    DATA : BEGIN OF PAST_DATE,
             YEAR(4)  TYPE N,
             MONTH(2) TYPE N,
             DAY(2)   TYPE N,
           END OF PAST_DATE.
    DATA : ONE_YEAR_BACK TYPE D.
    
    MOVE PRESENT TO PAST_DATE.
    
    SUBTRACT 1 FROM PAST_DATE-YEAR.
    ADD 1 TO PAST_DATE-DAY.
    MOVE PAST_DATE TO ONE_YEAR_BACK.

    hope that helps.

    Regards,

    Anand Mandalika.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Christian Wohlfahrt

      Hi,

      Christians comment on Anand Mandalika's code is correct.

      Since Dates are only integers with a mask the code can be corrected as follows:

      PARAMETERS : PRESENT TYPE D.

      DATA : BEGIN OF PAST_DATE,

      YEAR(4) TYPE N,

      MONTH(2) TYPE N,

      DAY(2) TYPE N,

      END OF PAST_DATE.

      DATA : ONE_YEAR_BACK TYPE D.

      MOVE PRESENT TO PAST_DATE.

      SUBTRACT 1 FROM PAST_DATE-YEAR.

      MOVE PAST_DATE TO ONE_YEAR_BACK.

      ADD 1 TO ONE_YEAR_BACK.

      Message was edited by: Erik Verbeeck

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.