Besho 87
Besho 87

Reputation: 35

Replace the year part of datetime data type in SQL Server 2005

I’m using SQL Server 2005 and I have a table contains a column of type datetime.

In this column, I have some dates with a wrong year, and I want to replace the year part only.

For example, I have this date 2009-01-07 08:47:00.000 and I want to replace the year part only to be 2010-01-07 08:47:00.000.

Notable to mention, I have so many records with wrong year, let’s say about 2000 records.

Thanks in advance and appreciating your help

Upvotes: 2

Views: 2706

Answers (1)

Andrey Adamovich
Andrey Adamovich

Reputation: 20663

You can use DATEADD function.

UPDATE mytable SET mydate = DATEADD(year, 1, mydate)

Upvotes: 2

Related Questions