How to return the date part only from a SQL Server datetime datatype

SELECT GETDATE()
Returns: 2008-09-22 15:24:13.790
I want that date part without the time part: 2008-09-22 00:00:00.000

Answer:

On SQL Server 2008 and higher, you should convert to date:
SELECT CONVERT(date, getdate())
On older versions, you can do the following:
SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, @your_date))
for example
SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))
gives me
2008-09-22 00:00:00.000
Pros:
  • No varchar<->datetime conversions required
  • No need to think about locale

http://stackoverflow.com/questions/113045/how-to-return-the-date-part-only-from-a-sql-server-datetime-datatype