SQL Date functions

By Tom / April, 27, 2009 / 0 comments

I always forget this so its here forever!

This is how to get the current Date..

CONVERT(varchar(8), GETDATE(), 112)

This is how to get the date from a datetime field

CONVERT(varchar(8), *InsertFieldHere*, 112))

Select queery to get the recoreds from a dateTime field for today..

SELECT     *
FROM         *Table*
WHERE     (CONVERT(varchar(8), GETDATE(), 112) == CONVERT(varchar(8), *InsertFieldHere*, 112)) ORDER BY Datetime