Click here to Skip to main content
15,899,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi I want to update a column only the date without the time change.
Posted
Comments
CHill60 5-Apr-14 8:53am    
What data type is the column?

Try this:

SQL
UPDATE
   Yourtable
SET
   datetimecol = DATEADD(day, DATEDIFF(day, datetimecol, getdate()), datetimecol)
 
Share this answer
 
Let say the new date is current date using getdate()
we can do this to get the date part:
convert(varchar, getdate(), 101)

we can also do this to get the time part of the old date time:
convert(varchar, datetimefield, 114)

So the idea is to concatenate the date part of a new date time with the time part of the old date time:
SQL
update table1 set datetimefield =
(convert(varchar, getdate(), 101) + ' ' + convert(varchar, datetimefield, 114))

As for the meanings of 101 and 104, refer this for more detail:
sql-convert[^]
 
Share this answer
 
v2

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