Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating datetime field

Status
Not open for further replies.

JBaileys

Technical User
Jun 23, 2003
244
US

Is there a way to update the date field, but keep the time field in tact.

Update table set [SurpriseDate] = datepart(mm,...)

Thanks,

jb
 
You cannot really remove the date component of a DateTime Field. You can, however, set all dates to Jan 1, 1900 while preserving the time component, like this...

Code:
declare @Temp Table(Data DateTime)

Insert Into @Temp Values('20060831 10:00:00')

Update @Temp Set Data = Data - DateDiff(Day, 0, Data)

Select * From @TEmp

Note that this is actually using a table variable so you can safely copy/paste this to Query Analyzer and run it without affecting any data in any tables.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top