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

How to subtract 1 from a date field???

Howdy,

I want to get the previous day to the one that is entered by the user. Thereofre I coded the following:

Code:

<b>DATA: lv_date TYPE date,

new_datab TYPE knvh-datab.

lv_date = new_datab.

lv_date = lv_date - 1. </b>

lv_date should now have the previous day to that entered in new_date.

However I ran it for today 01.03.2005 and it does not give me 28.02.2005?

Instead it gives me 00.03.2005????

Does anyone know why this would be occurring?

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    Posted on Mar 01, 2005 at 04:37 PM

    Make sure that your fields are "date" fields. Type sy-datum or type d.

    
    parameters: p_datum type sy-datum.
    
    p_datum = p_datum - 1.
    
    

    Regards,

    Rich Heilman

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Mar 01, 2005 at 04:46 PM

    Hi Steve,

    you should have value 20050301 in new_datab (internal format!).

    Then

    SUBTRACT 1 FROM lv_date.

    will work (at least date adding / subtracting is handled internally correct).

    Regards,

    Christian

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 01, 2005 at 04:58 PM

    You should be a doctor Rich! You've cured my headache 😊

    Do you know why type <b>date</b> does not work?

    Thanks again!

    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.