Friday 13 November 2009

SQL Server - How do I select just the date portion of a datetime field

There are a few ways to do this, but I find the easiest is to use the float version of a datetime and crop off the decimal portion (right of the decimal place is the time portion)

DECLARE @currentDate DateTime
SET @currentDate = Cast(Floor(Cast(GetDate() as Float )) As DateTime)