I have items with the properties :
public int ClientId {get;set;}
public DateTime StartDateTime{get;set;}
public DateTime EndDateTime{get;set;}
And I want to calculate the total of the difference between all the datetimes of each client with group by , but this :
var retVal = (from t items group t by ClientId into z
select new
{
ClientId = z.Key,
TimeSpanClientTotal = z.Sum(h => (h.EndDateTime - h.StartDateTime))
}).ToList();
Doesn't work since Sum
doesn't work well for TimeSpan
, which is the return value of the difference between two DateTime
s object .
Any suggestion how can I get the total TimeSpan of each client ?
Thanks
Enumerable.Sum
doesn't have aTimespan
overload – McnarySum
. – Booklet