Avatar of ITBenelux
ITBenelux
Flag for Belgium asked on

Update Date of datetime field without changing time

Hi does anyone know how to update a datepart?
or update the date

update table set datepart(dd, tablename) = '30'

What I want to do is udpate records date data but only the day
so where all of the records > '2009-07-25 00:00:00.000'
are updated to 30 i.e. 2009-07-30, I want to leave the timestamp portion alone in the records.

Thanks in advance.
Microsoft SQL Server 2008

Avatar of undefined
Last Comment
kaminda

8/22/2022 - Mon
Om Prakash

you can use dateadd function for this

Update table_name set field_name = DATEADD(d, 5, field_name) where field_name > '7/27/2009'

msdn link:
http://msdn.microsoft.com/en-us/library/ms186819(v=sql.90).aspx
ITBenelux

ASKER
I see, this code will add 5 day's.. I should used the real situation, my fault.
due to a development issue in the access front end.  all dates are set to 1/1/1900. I can update them based on the departure date, since these need to be the same.  
(see image)

Question is, if this is doable with the dateadd function ? My first intent was to update via datapart every part of the date without the risk to loose the time settings
Clipboard01.jpg
ASKER CERTIFIED SOLUTION
kaminda

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy