Update only the year in DATE in DB2.

RDBMS from IBM and IBM's Hierarchical DBMS and Transaction Manager (IMS DC).
Post Reply
Shamshir Rai Luthra
New Member
Posts: 4
Joined: Wed Aug 13, 2014 12:10 pm

Update only the year in DATE in DB2.

Post 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?
nicc
Global Moderator
Global Moderator
Posts: 691
Joined: Wed Apr 23, 2014 8:45 pm

Re: Update only the year in DATE in DB2.

Post by nicc »

set date_column = date_column arithmetica_sign number_of_years_to_adjust_by YEARS???
Regards
Nic
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

Re: Update only the year in DATE in DB2.

Post by William Collins »

You can use YEARS. There's a whole section on Date Arithmetic in your SQL Reference,
Shamshir Rai Luthra
New Member
Posts: 4
Joined: Wed Aug 13, 2014 12:10 pm

Re: Update only the year in DATE in DB2.

Post 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.
nicc
Global Moderator
Global Moderator
Posts: 691
Joined: Wed Apr 23, 2014 8:45 pm

Re: Update only the year in DATE in DB2.

Post 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?
Regards
Nic
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “IBM DB2 and IMS DB/DC”