Linq Query - Average Time (DateTime data types)

Posted by Jade on Stack Overflow See other posts from Stack Overflow or by Jade
Published on 2012-04-13T23:19:53Z Indexed on 2012/04/13 23:29 UTC
Read the original article Hit count: 187

Filed under:
|
|

I have a database that has the following records in a DateTime field:

2012-04-13 08:31:00.000
2012-04-12 07:53:00.000
2012-04-11 07:59:00.000
2012-04-10 08:16:00.000
2012-04-09 15:11:00.000
2012-04-08 08:28:00.000
2012-04-06 08:26:00.000

I want to run a linq to sql query to get the average time from the records above. I tried the following:

(From o In MYDATA Select o.SleepTo).Average()

Since "SleepTo" is a datetime field I get an error on Average(). If I was trying to get the average of say an integer, the above linq query works. What do I need to do to get it to work for datetimes?

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ