IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Date Month Manipulation


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
HameedAli

Active User


Joined: 16 Apr 2009
Posts: 151
Location: India

PostPosted: Sun Feb 13, 2011 10:14 pm
Reply with quote

Hi All
I have a table in which a column is a char field of length 20 in a table.
It contains date in first 10 positions and month in next 2 positions.
Code:

COL1     
------------
2011-01-3106

I'm trying to add the (SUBSTR(COL1,11,2) to (SUBSTR(COL1,1,10)and get the result as
Code:

COL1     
--------------------
2011-01-012011-06-31


Is it feasible to add like this? How to achieve this?
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sun Feb 13, 2011 10:41 pm
Reply with quote

Hello,

Suggest you think more about this. . .

There is no month 6 day 31. . . I suspect it would not be good to generate invalid data.
Back to top
View user's profile Send private message
Ronald Burr

Active User


Joined: 22 Oct 2009
Posts: 293
Location: U.S.A.

PostPosted: Mon Feb 14, 2011 3:37 am
Reply with quote

Untested:

UPDATE TABLENAME
SET COL1 = CHAR(SUBSTR(COL1,1,10)||CHAR(DATE(SUBSTR(COL1,1,10) + INT(SUBSTR(COL1,11,2)) MONTHS))
WHERE ?????;
Back to top
View user's profile Send private message
HameedAli

Active User


Joined: 16 Apr 2009
Posts: 151
Location: India

PostPosted: Mon Feb 14, 2011 10:53 am
Reply with quote

Excuse me for the confusion, it should be
Code:

COL1     
--------------------
2011-01-012011-06-30
Back to top
View user's profile Send private message
HameedAli

Active User


Joined: 16 Apr 2009
Posts: 151
Location: India

PostPosted: Mon Feb 14, 2011 12:09 pm
Reply with quote

Ronald Burr,
I tried with your query. it didn't work, Thanks for your effort
Back to top
View user's profile Send private message
HameedAli

Active User


Joined: 16 Apr 2009
Posts: 151
Location: India

PostPosted: Mon Feb 14, 2011 12:10 pm
Reply with quote

The following select clause helped me in achieving this.

Code:
SELECT DTE + MTHS MONTHS                 
 FROM  (                                 
SELECT    DATE(SUBSTR(COL1,1,10)) AS DTE ,
       INTEGER(SUBSTR(COL1,11,2)) AS MTHS
 FROM  Table1 ) AS Table2
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Mon Feb 14, 2011 2:55 pm
Reply with quote

talk about moving targets.

first you want to update a column: you provided expected results which showed an updated column.

next you complain about sql that was posted as untested.

then you provide a solution that does not satisfy your required results: you wanted to update a column.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Mon Feb 14, 2011 3:19 pm
Reply with quote

strong warning

for date related computation ( adding subtracting days, months, years )
before worrying about the technical issue ( as sadly everybody does over here )
everybody, repeat everybody, should be concerned more about the organization standards and practices...

the issue mostly relates to last day of the month and leap year processing..
there are general practices in place,
( it is accepted that adding one month to the Jan 29/30/31 will result on feb 28/29 )
the issue should anyway be brought to the attention of the powers of Your organization
for awareness and proper legalese !
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts Populate last day of the Month in MMD... SYNCSORT 2
No new posts Modifying Date Format Using DFSORT DFSORT/ICETOOL 9
No new posts JCL sort card - get first day and las... JCL & VSAM 9
No new posts Need to convert date format DFSORT/ICETOOL 20
Search our Forums:

Back to Top