By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,419 Members | 1,432 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,419 IT Pros & Developers. It's quick & easy.

DateTime - Get Average Time from multiple times

P: n/a
Hello all,

I have several DateTime objects and i want to get the average of all of them.

What would be the easiest way to do this?

Thanks
SN
Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"sho_nuff" <sh*********@yahoo.com> wrote:
I have several DateTime objects and i want to
get the average of all of them.
What would be the easiest way to do this?


private static DateTime AverageDateTime(params DateTime[] dateTimes)
{
long[] lngTicks = new long[dateTimes.Length];
long lngTotal = 0;

// Convert all DateTimes to ticks
for (int i = 0; i < dateTimes.Length; i++)
{
lngTicks[i] = dateTimes[i].Ticks;
lngTotal += lngTicks[i];
}

// Return the average as a DateTime
return new DateTime(lngTotal / lngTicks.Length);
}

P.

--
www.CL4.org
Nov 15 '05 #2

P: n/a
Thanks Paul, i discovered the 'ticks' property shortly after posting.

Thanks for the quick reply anyway.

SN

"Paul E Collins" <fi******************@CL4.org> wrote in message news:<c0**********@hercules.btinternet.com>...
"sho_nuff" <sh*********@yahoo.com> wrote:
I have several DateTime objects and i want to
get the average of all of them.
What would be the easiest way to do this?


private static DateTime AverageDateTime(params DateTime[] dateTimes)
{
long[] lngTicks = new long[dateTimes.Length];
long lngTotal = 0;

// Convert all DateTimes to ticks
for (int i = 0; i < dateTimes.Length; i++)
{
lngTicks[i] = dateTimes[i].Ticks;
lngTotal += lngTicks[i];
}

// Return the average as a DateTime
return new DateTime(lngTotal / lngTicks.Length);
}

P.

Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.