by thebeebs
3. July 2008 06:10
If you call GetDate you get todays date and time but what if you just want the date and not the time.
SQL provides no simple mechanism to do this but the solution below is probably the best way I’ve found:
CAST(FLOOR( CAST( GETDATE() AS FLOAT ) )AS DATETIME)
So a full example would be:
DECLARE @CurrentDate Datetime SET @CurrentDate = GETDATE() DECLARE @CurrentDateFloor Datetime SET @CurrentDateFloor = CAST(FLOOR( CAST( GETDATE() AS FLOAT ) )AS DATETIME) SELECT @CurrentDateFloor
2007–30-07 12:12:45 becomes 2007-30-07 00:00:00
553eb4e1-d50d-4e8d-9a52-15c3be15bd2f|1|2.0
Tags: