Xpode.com        Click here to Print this article.

Update Only Year in date in sql server with query

I need to update the year only and keep the rest same. Here under is my date format:

2011-03-18 00:35:13.000

Now run below query


UPDATE yourTable 
SET yourDateColumn = DATEADD(year,1,yourDateColumn)
WHERE someColumn = someValue

Example :

update tbuser set CreatedOnDate=DATEADD(year,1,CreatedOnDate) where id='2'

Here in example we tbuser is table name, createdonDate is field name. After executing query, Now the output in table will be 2012-03-18 00:35:13.000



http://
http://

Contributed by:
Rohit kakria
I am software developer

Resourse address on xpode.com
http://www.xpode.com/Print.aspx?Articleid=326

Click here to go on website