I have the following method which I planned to return a bunch of distinct date time objects. By distinct I means unique days (not including times).
The issue is, the the DateTime object have different times, and are therefore evaluating as unique even though they're the same day.
How can I have the query ignore the time part of the date and just evaulate the date for uniqueness?
public List<DateTime> DistinctNoticeDates()
{
return (from notices in this.GetTable<Notice>()
orderby notices.Notice_DatePlanned descending
select notices.Notice_DatePlanned).Distinct().ToList();
}
Thanks.
Try using the Date
property to get just the date of DateTime
structure:
public List<DateTime> DistinctNoticeDates()
{
return (from notices in this.GetTable<Notice>()
orderby notices.Notice_DatePlanned descending
select notices.Notice_DatePlanned.Date)
.Distinct()
.ToList();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With