Robin Hames

Hints, tricks and tips relating to MS SQL Server and .NET
posts - 14 , comments - 45 , trackbacks - 0

SQL Server datetime - getting the date part only

I am always forgetting the format for using DATEADD and DATEPART functions to get just part of a SQL Server datetime (e.g. just the date), so I am posting it here so I’ll always know where to find it.
declare @date datetime
set @date = getdate()
 
select @date, dateadd(day, datediff(day, 0, @date), 0)
 

Print | posted on Wednesday, November 19, 2008 3:17 PM | Filed Under [ SQL Server ]

Feedback

Gravatar

# re: SQL Server datetime - getting the date part only

Remember that in SQL Server 2008, you can use CAST with the new Date type to get the same results.
11/19/2008 6:01 PM | Christopher Reed
Post A Comment
Title:
Name:
Email:
Comment:
Verification:
 
 

Powered by: