Mrdenny
46795 pts. | Mar 6 2008 7:56PM GMT
Check out my SQL Server blog “SQL Server with Mr Denny” for more SQL Server information.



SELECT CONVERT(DATETIME, CONVERT(VARCHAR(10), GETDATE(), 101))This code converts the value into a character string of just the date, then converts that back to a datetime data type. The time will still be included, but it will be reset to midnight.
SELECT DATEADD(dd, DATEDIFF(dd, 0, GETDATE()), 0)Here the base date is 0 (i.e. Jan 1 1900 or whatever it is), and we count the number of days from the base date to today using DATEDIFF, then add them back. The result is the beginning of the interval, i.e. the beginning of today.
SELECT DATEADD(mm, DATEDIFF(mm, 0, GETDATE()), 0)The nice part about this approach is that date arithmetic is a lot faster than string conversion.


Mrdenny
46795 pts. | Mar 6 2008 7:56PM GMT
Check out my SQL Server blog “SQL Server with Mr Denny” for more SQL Server information.
