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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 date problem

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/2001
01/01/2002

i want to set the year to 2005 without changing month and date...

the resultant will be as follows...

dt
------
12/12/2005
01/01/2005

thanks in advance...


jasper_smith
SQL Server MVP & SQLTeam MVY

846 Posts

Posted - 2002-07-04 : 04:57:00
update MYTABLE
set DATECOL = cast('2005' + RIGHT(convert(char(8),DATECOL,112),4) as datetime)


HTH
Jasper Smith
Go to Top of Page

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 MyTable
SET dt = DATEADD(yy, DATEDIFF(yy, dt, '2005-01-01'), dt)


Edited by - Arnold Fribble on 07/04/2002 06:51:51
Go to Top of Page
   

- Advertisement -