Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
ravilobo
Master Smack Fu Yak Hacker
1184 Posts |
Posted - 2002-07-04 : 04:45:55
|
| Hi I have the follwoing problem in sql...I have a date column in a table...for e.g dt------12/12/200101/01/2002i want to set the year to 2005 without changing month and date...the resultant will be as follows... dt------12/12/200501/01/2005thanks in advance... |
|
|
jasper_smith
SQL Server MVP & SQLTeam MVY
846 Posts |
Posted - 2002-07-04 : 04:57:00
|
| update MYTABLEset DATECOL = cast('2005' + RIGHT(convert(char(8),DATECOL,112),4) as datetime) HTHJasper Smith |
 |
|
|
Arnold Fribble
Yak-finder General
1961 Posts |
Posted - 2002-07-04 : 06:33:58
|
| Doesn't work for leap years. I'd use this instead.UPDATE MyTableSET dt = DATEADD(yy, DATEDIFF(yy, dt, '2005-01-01'), dt)Edited by - Arnold Fribble on 07/04/2002 06:51:51 |
 |
|
|
|
|
|