How to convert datetime to date only (with time set to 00:00:00.000)
问题 I have a string '2009-06-24 09:52:43.000', which I need to insert to a DateTime column of a table. But I don't care about the time, just want to insert it as 2009-06-24 00:00:00.000 How can I do that in T-SQL? 回答1: For SQL Server 2005 and below: CONVERT(varchar(8), @ParamDate, 112) -- Supported way CAST(FLOOR(CAST(@ParamDate AS float)) AS DATETIME) -- Unsupported way For SQL Server 2008 and above: CAST(@ParamDate AS DATE) 回答2: declare @originalDate datetime select @originalDate = '2009-06-24