Slight bias to SQL Server
- Best approach to remove datetime time part in SQL Server
- The most efficient way in SQL Server to get dates from date + time?
Summary
DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0)
SQL Server 2008 is of type date . Therefore just use
CAST(GETDATE() AS DATE)
Edit: add one day, compare with day to "zero"
DATEADD(day, DATEDIFF(day, -1, GETDATE()), 0)
From cyberkiwi:
An alternative that does not include 2 functions is (+1 may be in brackets or on our sides).
DATEDIFF(DAY, 0, GETDATE() +1)
DateDiff returns a number, but for all purposes it will work as the date where you intend to use this expression, except for converting it directly to VARCHAR - in this case you would use the CONVERT approach directly in GETDATE (), for example,
convert(varchar, GETDATE() +1, 102)
gbn Jan 26 '11 at 9:15 2011-01-26 21:15
source share