Link to home
Start Free TrialLog in
Avatar of ITBenelux
ITBeneluxFlag 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.
Avatar of Om Prakash
Om Prakash
Flag of India image

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
Avatar of 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
Avatar of kaminda
kaminda
Flag of Sri Lanka image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial