0

My data is like below

2010-11-09 13:20:02.000

I'd like to get date only. Which sql function will i use?

soclose
  • 2,773
  • 12
  • 51
  • 60
  • SQL Server 2008 (or newer) has a `DATE` datatype for this exact purpose... – marc_s Mar 01 '11 at 09:14
  • Possible dublicates of http://stackoverflow.com/questions/3283039/tsql-strip-date-from-datetime and http://stackoverflow.com/questions/1124808/need-only-date-from-datetime. – Oleks Mar 01 '11 at 09:21

1 Answers1

0

My preference (because of its flexibility) is DATEADD/DATEDIFF:

SELECT DATEADD(day,DATEDIFF(day,0,'2010-11-09T13:20:02.000'),0)

It's flexible, because you can use the same pattern to achieve other rounding effects. E.g. to get the first of the month, you can dateadd/datediff month rather than day. It can also be used to find, e.g. the end of the month for the given date, or the end of the month, 3 months from the given date.

Damien_The_Unbeliever
  • 234,701
  • 27
  • 340
  • 448