title: Filter by time range in list of DateTime objects
body: <p>I have a list of DateTime objects.</p>
  
  <p>I need to take from this list only those objects that have time part of the date between '00:00:01' and '12:00:00'.</p>
  
  <p>How can I query this list?</p>
  
  <p>If I would make a SQL Query I would do something this way</p>
  
  <pre><code>SELECT TspCreated,
      CASE 
          WHEN cast(TspCreated as time) &gt; '00:00:00' AND 
               cast(TspCreated as time) &lt;= '12:00:00' 
               THEN '00 - 12'
          WHEN cast(TspCreated as time) &gt; '12:00:00' AND 
               cast(TspCreated as time) &lt;= '18:00:00' 
               THEN '12 - 18'
          WHEN cast(TspCreated as time) &gt; '18:00:00' AND 
               cast(TspCreated as time) &lt;= '23:59:59' 
               THEN '18 - 24'
      END AS TimeFrame
  FROM MyTable
  </code></pre>
  
  <p>EDIT: </p>
  
  <p>Thanks to <a href="https://stackoverflow.com/questions/27071839/filter-by-time-range-in-list-of-datetime-objects/27071954#27071954">Jon Skeet answer</a> I had the way to use Timespan objects as the boundaries for my query. Unfortunately, in my case that answer is not applicable because Linq-to-Entities does not support usage of <code>TimeOfDay</code> property. I have ended up with usage of <a href="http://msdn.microsoft.com/en-us/library/vstudio/bb738563%28v=vs.110%29.aspx" rel="nofollow noreferrer">Entity Framework Canonical Functions</a>:</p>
  
  <pre><code>TimeSpan ts_0 = new TimeSpan( 0, 0, 0 );
  TimeSpan ts_12 = new TimeSpan( 12, 0, 0 );
  int NumOfIssues = ctx.MyEntitySet.Where( x =&gt; 
                        DbFunctions.CreateTime( x.TspUsed.Hour, x.TspUsed.Minute, x.TspUsed.Second ) &gt;= ts_0 &amp;&amp;
                        DbFunctions.CreateTime( x.TspUsed.Hour, x.TspUsed.Minute, x.TspUsed.Second ) &lt; ts_12).Count();
  </code></pre>