SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Express Edition and Compact Edition (2005)
 How to change Dates in database
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

martinhogan
Starting Member

South Africa
5 Posts

Posted - 01/13/2012 :  08:24:14  Show Profile  Reply with Quote
HI,
I have a database with Date field that needs to be changed from
1975 to 2011. Problem is, I only want to change the year, a not
the day and month.

In short change 1975\09\05 to 2011\09\05
1975\09\06 to 2011\09\06

Please help
Thanks

Martin Hogan

Martin Hogan

sunitabeck
Flowing Fount of Yak Knowledge

5152 Posts

Posted - 01/13/2012 :  08:30:18  Show Profile  Reply with Quote
Depending on what the data type of the column is you could do it using dateadd or replace as shown below. If your column is datetime type (and assuming you want to replace all rows etc.)
UPDATE YourTable SET YourDateCol = DATEADD(YEAR,36,YourDateCol); -- add 36 years
If it is character type:
UPDATE YourTable SET YourDateCol = REPLACE(YourDateCol,'1975','2011');; -- replace 1975 with 2011
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
48102 Posts

Posted - 01/14/2012 :  01:03:17  Show Profile  Reply with Quote
same as

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=170168

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000