/ Published in: SQL
Returns the date associated with a given datetime value (@date).
Expand |
Embed | Plain Text
DATEADD(d, DATEDIFF(d, 0, @date), 0)
Comments
Subscribe to comments
You need to login to post a comment.

Awesome, thanks!
I have tested and your technique is the fastest option, even with the Date data type in SQL 2008.
Try this:
DECLARE @Table TABLE ( Date1 datetime ,Date2 datetime ,Date3 date ) DECLARE @i int SET @i = 0 WHILE (@i < 1000000) BEGIN INSERT INTO @Table SELECT GetDate() + @i, null, null SET @i = @i + 1 END DECLARE @Timer datetime SET @Timer = getdate() UPDATE @Table SET Date2 = Date1, Date3 = Date1 PRINT 'Warm Up' PRINT DateDiff(ms, @Timer, getdate()) SET @Timer = getdate() update @Table Set Date2 = CONVERT(DATETIME, SUBSTRING(CONVERT(varchar, Date1), 1, 11)) PRINT '(English Culture only) Parse with SubString to DateTime' PRINT DateDiff(ms, @Timer, getdate()) SET @Timer = getdate() update @Table Set Date2 = CONVERT(varchar, Date1, 101) PRINT 'Convert to Varchar 101 to DateTime' PRINT DateDiff(ms, @Timer, getdate()) SET @Timer = getdate() update @Table Set Date2 = CONVERT(DATE, Date1) PRINT '(SQL2008 only) Convert from DateTime to Date to Datetime' PRINT DateDiff(ms, @Timer, getdate()) SET @Timer = getdate() update @Table Set Date3 = Date1 PRINT '(SQL2008 only) Convert from DateTime to Date' PRINT DateDiff(ms, @Timer, getdate()) SET @Timer = getdate() update @Table Set Date2 = DATEADD(d, DATEDIFF(d, 0, Date1), 0) PRINT 'Use DateDiff then DateAdd' PRINT DateDiff(ms, @Timer, getdate())