I am trying to calculate time difference between 2 date and want to get day name of my date.
For Ex.: 4/7/2016
- Day: Monday
Here is my class:
public class Attendance
{
public int Id { get; set; }
public Nullable<System.DateTime> StartDateTime { get; set; }
public Nullable<System.DateTime> EndDateTime { get; set; }
}
When I am trying to do this:
var query = (from t in context.Attendance
select new
{
timeDiff=t.EndDateTime.Value.Subtract(t.StartDateTime.Value).TotalHours,
Day=System.StartDateTime.ToString("dddd");
}).tolist();
Error
LINQ to Entities does not recognize the method 'System.TimeSpan Subtract(System.DateTime)' method, and this method cannot be translated into a store expression
I don't want to do like below:
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();
I have Datetime
in format like this stored in my tables and so I want expected output like below shown in difference field:
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