vinaypugalia (4/6/2010)
Great handy article !!However, we can also achieve the same through -
SELECT CONVERT(DATETIME,DATEDIFF(dd,0,GETDATE()))
This way we can save the time taken to perform DATEADD operation though it would be quite marginal....
An interesting idea. It does seem to perform slightly better. Here's a proof using my 200K row Tally Table.
SELECT DATEADD(d, DATEDIFF(d,0,GETDATE()), 0) A
INTO #2
FROM Util..Tally
SELECT CONVERT(DATETIME,DATEDIFF(dd,0,GETDATE())) A
INTO #1
FROM Util..Tally
DROP TABLE #1
DROP TABLE #2
(200000 row(s) affected)
SQL Server Execution Times:
CPU time = 78 ms, elapsed time = 95 ms.
(200000 row(s) affected)
SQL Server Execution Times:
CPU time = 62 ms, elapsed time = 93 ms.