MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

change year portion of db2 date field

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
tcurrier
Intermediate


Joined: 10 Feb 2006
Posts: 188
Topics: 68

PostPosted: Wed May 19, 2010 5:51 pm    Post subject: change year portion of db2 date field Reply with quote

Hello,

I have a DB2 date column with various dates and I want to change the 'year' (ccyy) portion of all the dates to '2010' ....

e.g.

2006-10-05
2008-02-10
2009-03-20

to :

2010-10-05
2010-02-10
2010-03-20

Thanks for any help.....
Back to top
View user's profile Send private message
NASCAR9
Intermediate


Joined: 08 Oct 2004
Posts: 274
Topics: 52
Location: California

PostPosted: Wed May 19, 2010 6:40 pm    Post subject: Reply with quote

tcurrier,

this works, not sure how efficient it is.
Code:



set your_date = your_date + (SELECT  YEAR('2010-12-31'  - your_date )
                    FROM SYSIBM.SYSDUMMY1  ) YEARS   

_________________
Thanks,
NASCAR9
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12369
Topics: 75
Location: San Jose

PostPosted: Wed May 19, 2010 7:07 pm    Post subject: Reply with quote

tcurrier,

You can also use this

Code:

UPDATE TABLE                                   
   SET DATE_COL = DATE_COL + (INT(2010) - YEAR(DATE_COL)) YEARS
 ;                                                 


Kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
tcurrier
Intermediate


Joined: 10 Feb 2006
Posts: 188
Topics: 68

PostPosted: Wed May 19, 2010 7:57 pm    Post subject: Reply with quote

amazing.... thank you both !
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group