LINQ filtering items within the list between two specified dates
<p>I have a List of type like following:</p>

<pre><code>class GroupedItem
{
  public DateTime _Date {get;set;}
  pubilc int sales {get;set;}
}
</code></pre>

<p>Where the list is defined as:</p>

<pre><code>List&lt;GroupedItem&gt; _groupedItems = new List&lt;GroupedItem&gt;();
</code></pre>

<p>I'd like to remove all items from list starting from DateTime.Now and into past 7,14, 21 or 30 days from the list by somehow specifying this using LINQ...</p>

<p>How could I do this ?</p>

<p>Edit: the method I've tried is like following:</p>

<pre><code>  var selectedDates = Enumerable
    .Range(0, int.MaxValue)
    .Select(index =&gt; new DateTime?(StartDate.AddDays(index)))
    .TakeWhile(date =&gt; date &lt;= EndDate)
    .ToList();
</code></pre>

<p>But this returns me empty list... </p>

<p>Edit: Guys, how could I do the following:</p>

<pre><code>   var date_range = Int32.Parse(Session["drange"].ToString());
                ViewBag.LineGraph = _groupedItems
                      .GroupBy(l =&gt; l._Date.Date)
                      .Select(cl =&gt; new GroupedItem
                      {
                           _Date = cl.Key,
                           Sales = cl.Sum(c=&gt;c.Sales)
                      })
                      .OrderBy(x =&gt; x._Date)
                      .Where(t =&gt; t._Date &lt;= DateTime.Now &amp;&amp;
                      t._Date &gt;= DateTime.Now.Subtract(TimeSpan.FromDays(date_range)))
                      .ToList();
</code></pre>

<p>Is there a way to upgrade this and to remove only dates which are not in the time range given by the parameters (which is Today's date - DateTime.Now and - 7 days into the past... </p>

<p>For example if I have date 14th of December, that one would be removed, but the one from 18th isn't since it' belongs to those 7 days range... ?</p>