Tuesday, December 28, 2010

Getting only Date part from a data time column

here is the way:
SELECT DATEADD(D, 0, DATEDIFF(D, 0, GETDATE()))

and if you have a column of datetime type in your DB and you want to use it in where clause to get the records that matches a date and your DB has values with time also, then you need to use query like this.


SELECT * FROM TableThathasDateTimeColumn where
DATEADD(D, 0, DATEDIFF(D, 0, modifiedate)) = (SELECT convert(datetime, '2010.12.14', 102) )

this will return all recrods from TableThathasDateTimeColumn table that has modified date of December 14, 2010 , irrespective of time that presensts in modifiedate column.

No comments:

Post a Comment