473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

DateTime - Get Average Time from multiple times

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
2 12454
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Symon R | last post by:
This is a bit of a weird one that I haven't yet been able to solve - I'm hoping someone out there can disprove my findings and tell me where I've gone wrong! I have designed a web service that...
8
by: Alex | last post by:
My table is laid out as such: ID (int) What (varchar 20) TimeStamp (smalldatetime) ------- ------------- --------------- 73 Start ...
2
by: ThomasR | last post by:
I've done some examination of the DateTime implementation (stepped through Disassembly in debug mode) and find it horribly inefficient in framework 1.0. For example, the internal DatePart...
15
by: Fritz Switzer | last post by:
I'd like to have a string assigned the value of a DateTime.AddMinutes(amount) so that the string is formatted in "HH:MM" format. For example: DateTime.Now.AddMinutes(30) returns "00:30" ...
4
by: Mark | last post by:
Is there a way to convert a char to a DateTime without first converting to a string and using DateTime.Parse or ParseExact? I'm trying to reuse the char which can be reused instead of converting...
6
by: J | last post by:
Kind of new at programming/vb.net. I'm doing this junky die roller program. Heres's what is supposed to happen: Roll 2 6-sided dies. Add rolls together put total in rolls(d6total). Display...
2
by: jarosciak | last post by:
Hi everyone, I need a little bit of help with this problem. I've got a time durations feed, which comes in this format (minutes:seconds): Example, there is only 5 values:
1
by: wetsprockets | last post by:
Hello, I have two tables, WindVector (wind data) and DOH_FC88to07 (water quality samples). The WindVector table has the following fields: Date (short date) Time (short time) WindSpeed...
0
yasirmturk
by: yasirmturk | last post by:
Standard Date and Time Functions The essential date and time functions that every SQL Server database should have to ensure that you can easily manipulate dates and times without the need for any...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.