Tuesday, May 10, 2011

Update only month and day of a date in SQL server

Well..sometimes Woopse happens...

We had begin dates and end dates in our database ....well somehow they got all wrong dates... years were correct and hence began the update process


Update TableName
Set End_Date =CONVERT(datetime, Convert(varchar(4),DATEPART(Year, End_Date))+'-05-01 00:00:00.000')
where (DATEPART(MONTH, End_Date)='05' and DATEPART(DAY, End_Date) != '01')

Spiffy !!!

Also, my running is going awesome... SO far so good 

No comments: