SQLTeam.com | Weblogs | Forums

How to truncate the date in sql server



Hi All,
i am very new in SQL , in my database date is stored as below and when i am trying to view the particular message by filter date, cannot truncate it

2015-06-07 09:10:41.817

like if i want to view the messages for only 2015-6-07 , not all how i can filter, kindly help.

say i wanted to view the messages created on 07th june and ima setting the date filter as date = '2015-06-07' this is not working as this one is storing time as well which i dont need.

2015-06-07 09:10:41.817

WHERE datecol >= '2015-06-07' 
AND   datecol <  '2015-06-08'


missing a closing apostrophe. Also generally better to use locale-independent dates (yyyymmdd, no hyphens) Try this instead:

WHERE datecol >= '20150607'
AND   datecol <  '20150608'