Skip to Content
author's profile photo
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 comment
10|10000 characters needed characters exceeded

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 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 comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    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 comment
    10|10000 characters needed characters exceeded

    • I would say because that data element "date" uses the domain CHAR08 which is a CHAR data type. On the other hand, data element "sydatum" uses the domain SYDATS which is a DATS data type.

      Regards,

      Rich Heilman