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 > Add months to a date of type int with format YYYYMMDD

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-15-11, 21:35
leason2 leason2 is offline
Registered User
 
Join Date: Dec 2010
Location: Tacoma, Wa
Posts: 3
Add months to a date of type int with format YYYYMMDD

I am using db2 UDB400.
I am querying the transaction date, which is of Type INT formatted as YYYYMMDD. I need to add ex. 6 months to this date, then divide by 6 to get AVG usage for 6 months.
Ideally, if I can just add months to this format, I can change the months out to a parameter in Crystal reports.
Any help is greatly appreciated!

Luke
Reply With Quote
  #2 (permalink)  
Old 01-16-11, 02:11
tonkuma tonkuma is online now
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,195
Quote:
I need to add ex. 6 months to this date,
Although I don't know so much about DB2 for iSeries,
I don't think that you can add months to INT value directly.

An idea I thought was ...
1) Convert the INT value to a valid date string.
2) CAST the string to date.
3) Add months.

Here is a sample expression.
DATE( TRANSLATE( 'abcd-ef-gh' , DIGITS(transaction_date) , '..abcdefgh' ) ) + 6 MONTHs

Quote:
then divide by 6 to get AVG usage for 6 months.
I couldn't understand it.
divide WHAT by 6?
"divide date by something" may be nonsense.
Reply With Quote
Reply

Tags
date format add months

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