February 16, 2016

Return Date Part from DATETIME - SQL Server

Most of the time we need date part only from datetime format in SQL Server. 

1) Old method
 SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))



2) On SQL Server 2008 and higher
SELECT CONVERT(DATE, GETDATE()) 



Above two methods helps to keep original date format and returns date part only from datetime.

3) If you want in specific date format (US date format)
SELECT CONVERT(CHAR,GETDATE(),101)


No comments: