Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL2000 SQL-server-2005 SQL , +
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 29-Jan-10 23:53pm
Edited 2-Feb-10 9:29am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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);
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You know, your coding would go A LOT faster if you used google:
 
http://msdn.microsoft.com/en-us/library/ms186724.aspx[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

THIS IS THE TESTED SOLUTION.
 
update personnaldetails
set dbdate = dateadd(day,(29-datepart(dd,dbdate)),dbdate)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

THIS IS THE TESTED SOLUTION.
 
update personnaldetails
set dbdate = dateadd(day,(29-datepart(dd,dbdate)),dbdate)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

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))
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 8,488
1 OriginalGriff 6,516
2 Peter Leow 3,647
3 Zoltán Zörgő 3,416
4 Richard MacCutchan 2,397


Advertise | Privacy | Mobile
Web03 | 2.8.150123.1 | Last Updated 27 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100