Page 1 of 1

Update only the year in DATE in DB2.

Posted: Mon Jan 18, 2016 12:04 pm
by Shamshir Rai Luthra
Hi,

Using a DB2 query I need to update only the year of a date. The date is defined in DATE format. Can we do this? I could not find a way of doing this?
Can anyone help please?

Re: Update only the year in DATE in DB2.

Posted: Mon Jan 18, 2016 2:44 pm
by nicc
set date_column = date_column arithmetica_sign number_of_years_to_adjust_by YEARS???

Re: Update only the year in DATE in DB2.

Posted: Mon Jan 18, 2016 4:14 pm
by William Collins
You can use YEARS. There's a whole section on Date Arithmetic in your SQL Reference,

Re: Update only the year in DATE in DB2.

Posted: Tue Feb 09, 2016 11:47 am
by Shamshir Rai Luthra
Hi,

I have tried with this:

Code: Select all

UPDATE table
SET YEAR(DATE) = 2017 
WHERE 
YEAR(DATE) = 2016;
But it did not work.

Re: Update only the year in DATE in DB2.

Posted: Tue Feb 09, 2016 2:44 pm
by nicc
But it did not work.
That is a big waste of time. It conveys no information execept that in SOME way known ONLY TO YOU that it did not have the desired effect.
Is that syntax as per the manual which you were advised to consult? Did you try any other methods e.g. adding 1 year to you date field?