Help with an Aggregate Calculation Sum( DateTime ) in a DataTable

E

edcha

I am trying to use the following Aggregate Calculation.
string time = trabajadoresTable.Compute ( "Sum(DateTime)" ,
"") .ToString();

I need to sum the hours in a column with type DateTime.
If they be numbers this work good
"trabajadoresTable.Compute("Sum(pago)", "")"
But with the type DateTime's in a column make me the following error


In the System.Data.DataException was generated the error:
Invalid use of Aggregate Calculation Sum( ) and the type DateTime.

how I sum the hours in one column if it the type is DateTime


Thanks
 
M

Marc Gravell

loop and accumalate...

int hours = 0;
foreach(blah row in records)
{
hours += row.DateField.Hour;
}

If you have LINQ you can do it inline:

int hours = records.Sum(row => row.DateField.Hour);

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top