Linq2Sql how to get all distinct dates without time part
linq-to-sql
Solution
Use the `Date` property of the `DateTime` type.
var dates = from c in db.Comments
group c by c.Time.Date into g
orderby g.Key
select g.Key;
or
var dates = (from c in db.Comments
select c.Time.Date).Distinct().OrderBy(d => d);
An SQL expert can tell you which of these is better.
Problem
I'm using SQL Server 2005 express I have a datetime field in a table witch contains date and time. I want to select distinct the dates from the table ignoring the time part. I used this code but the order by is ignored ! (the generated sql doesn't contain order by) : ``` var dates = (from c in db.Comments orderby c.Time descending select c.Time.Day + "/" + c.Time.Month + "/" + c.Time.Year).Distinct(); ``` Any ideas on how to do this are welcome. Thanks