Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2007
    Posts
    6

    Unanswered: How to subtract date in DB2

    Hi all,

    I have a question. How do we subtract date2 from date1 in DB2?

    I am trying to alter the table to add a generated always column which subtracts one date fromn the other which goes as follows.

    db2 "alter table schema.tabname add GENDATE AS generated always as GENDATE(days(ALTERNATEDATE) - days(CONTROLDATE))"

    But i keep getting error. When i try to drop the table and recreate it it works fine. please help me.

    Thanks in advance

  2. #2
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    You just substract the date values:
    Code:
    VALUES CURRENT_DATE - DATE('2007-10-10')
    
    1
    ----------
           22.
    
      1 record(s) selected.
    DB2 returns a "duration", not a new date, of course.

    What you are doing above is substracting two integers - not two dates. Which error message do you get?

    Which version of DB2 are you using on which platform?
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •