If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > How to subtract date in DB2

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-01-07, 10:39
viper9 viper9 is offline
Registered User
 
Join Date: Jul 2007
Posts: 6
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
Reply With Quote
  #2 (permalink)  
Old 11-01-07, 12:00
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On