Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear All,

I'm stuck in a situation where I have to update 60000 records date. I just want to update the date but that means if the date is 23.04.1980 and 10.09.1989 then I just want to update the date i.e. 23 & 10 only to date like 09.04.1980 & 09.09.1989 keeping the rest month and year untouched. Is this possible?

Please provide me solution of this. I have tried datepart to do this but that update the whole date to year 1900 which is wrong. Also dateadd not work here because the dates are different.
Posted
Updated 2-Feb-10 8:29am
v2

THIS IS THE TESTED SOLUTION.

SQL
update personnaldetails
set dbdate = dateadd(day,(29-datepart(dd,dbdate)),dbdate)
 
Share this answer
 
I do not know if this can be easly use SQL to achive this. I would put SELECT query to get a list and then for each record I would fetch into DateTime type. Then update with updated date.

Example to modify DateTime:

DateTime dt = DateTime.Now.Date.AddDays(2);
dt = dt.AddMonth(1);
dt = dt.AddYear(1);
 
Share this answer
 
You know, your coding would go A LOT faster if you used google:

http://msdn.microsoft.com/en-us/library/ms186724.aspx[^]
 
Share this answer
 
This query:
update table
set date = DateAdd(dd, 9-DatePart(dd, date), date)

would update the table table and set the column date to the 9th of the month leaving the month and year (and time) values untouched.

I hope this helps
 
Share this answer
 
THIS IS THE TESTED SOLUTION.

update personnaldetails
set dbdate = dateadd(day,(29-datepart(dd,dbdate)),dbdate)
 
Share this answer
 
in case you want to just change the day as '9' of all records


Update TableName set yourDate = cast(Month(yourDate) as varchar(2)) + '/9/' + Cast(Year(yourdate) as varchar(4))
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900