Calculating time difference on datetime object in Entity Framework giving error
<p>I am trying to calculate time difference between 2 date and want to get day name of my date.</p>

<p>For Ex.: 4/7/2016</p>

<ul>
<li>Day: Monday</li>
</ul>

<p>Here is my class:</p>

<pre><code>public class Attendance
{
      public int Id { get; set; }
      public Nullable&lt;System.DateTime&gt; StartDateTime { get; set; }
      public Nullable&lt;System.DateTime&gt; EndDateTime { get; set; }
}
</code></pre>

<p>When I am trying to do this:</p>

<pre><code> var query = (from t in context.Attendance
              select new 
              {
                 timeDiff=t.EndDateTime.Value.Subtract(t.StartDateTime.Value).TotalHours,
                 Day=System.StartDateTime.ToString("dddd");
              }).tolist();
</code></pre>

<p>Error</p>

<blockquote>
  <p>LINQ to Entities does not recognize the method 'System.TimeSpan
  Subtract(System.DateTime)' method, and this method cannot be
  translated into a store expression</p>
</blockquote>

<p>I don't want to do like below:</p>

<pre><code> var query = (from t in context.Attendance.toList().
                  select new 
                  {
                     timeDiff=t.EndDateTime.Value.Subtract(t.StartDateTime.Value).TotalHours,
                     Day=System.StartDateTime.ToString("dddd");
                  }).tolist();
</code></pre>

<p>I have <code>Datetime</code> in format like this stored in my tables and so I want expected output like below shown in difference field:</p>

<pre><code>startDatetime              Enddatetime                Difference
----------------------------------------------------------------
2016-06-29 15:52:32.360    2016-06-29 15:52:36.970    00:00:04
2016-06-29 15:53:32.360    2016-06-29 15:55:36.970    00:2:00
2016-06-29 15:53:32.360    2016-06-29 16:55:36.970    01:02:00
</code></pre>