Connecting Tech Pros Worldwide Forums | Help | Site Map

Updating only the year in a date

Newbie
 
Join Date: Aug 2009
Posts: 1
#1: Aug 12 '09
I want to change the Year in Date . For example 01.02.0009 into 01.02.2009

Please suggest how can I do it in DB2...?

I tried the below code but it is giving Illegal symbol error for '('

UPDATE table
SET YEAR(DATE) = 1234
WHERE
YEAR(DATE) = 2006;

docdiesel's Avatar
Moderator
 
Join Date: Aug 2007
Location: Munich
Posts: 289
#2: Aug 12 '09

re: Updating only the year in a date


Hi,

in sql you've got to update the field, not a functions result of a field.

The where clause is ok, but you've got to assemble the set instruction with string concatenation, like

set datecolname = date( concat( year(datecol)+1900, "-", month(datecol), "-", day(datecol) ) )

which does not handle the days and month <10 yet.

Regards

Doc Diesel
Reply