473,785 Members | 3,032 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to find the average duration from these values?

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:second s):
Example, there is only 5 values:
00:45
01:15
00:12
00:53
03:42
I need to find the average duration from these 5 values.
Can someone help me to figure out how to do this in C#.NET?
Thanks
Joe

Jul 6 '06 #1
2 7163
Hi Joe,

This is just sample code but you could adapt it to your needs. One
approach is to use TimeSpan.Parse( ) to get what you want. You'll need
to be careful that the input strings are all formatted correctly. The
TimeSpan.Parse( ) routine expects hh:mm and not mm:ss, so I prepended
"00:" for the hours. Then it's just a matter of doing the average:

string[] times = { "00:45", "01:15" , "00:12", "00:53", "03:42" };
TimeSpan totalTime = new TimeSpan();
foreach (string time in times)
totalTime += TimeSpan.Parse( "00:" + time);
long averageTicks = (totalTime.Tick s / times.Length);
Console.WriteLi ne("The average is {0}", new TimeSpan(averag eTicks));

Like I said, you'll probably want to do some error handling in there
but you get the gist.
Hope that helps,
John

ja*******@gmail .com wrote:
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:second s):
Example, there is only 5 values:
00:45
01:15
00:12
00:53
03:42
I need to find the average duration from these 5 values.
Can someone help me to figure out how to do this in C#.NET?
Thanks
Joe
Jul 6 '06 #2
This had helped a lot and I was able to figure it out.
Thank you so much.
Joe

Jul 6 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
4405
by: Sara | last post by:
I am trying to find the average number of products of the set that is on rows...dynamically. For example, if I had states on rows and was looking at the average number of products, I would see this IN 72 MI 66 AL 88
8
1702
by: Alex | last post by:
My table is laid out as such: ID (int) What (varchar 20) TimeStamp (smalldatetime) ------- ------------- --------------- 73 Start <T1> 73 Misc <T2> 73 End <T3> 81 Start <T1'> 81 Misc <T2'> 81 End <T3'>
1
2245
by: Dave | last post by:
Greetings, I am trying to create a duration field in a query. I have a field with a start time and a field with an end time. They are both in military time, and are formatted as hours:minutes. I am trying to create a duration field by subtracting the start time from the end time. This is working. However, some end times do not happen until the following day, and this is screwing up the results. If the start time is 04:30 and the
3
1023
by: muskito.net | last post by:
Hi, I Have the following code: Public Sub UpdateEvent(ByVal ID As Integer, _ ByVal StartTime As Integer, _ ByVal Duration As Integer) EventId = ID Dim EventToUpdate As SchedulerEvent = SchedulerEvents.Find(AddressOf FindById)
0
1895
by: Saloni | last post by:
I have windows service which is going to run on several machines which are in different time zones in USA. I want to find out the Eastern Zone current time from these different machines. It should return me correct time based on timezone(GMT-4 for DST duration/GMT-5 for non DST duration) Is there any simplest way to do this. Logic which i used is as below: 1.Find Current local time 2.Find GMT time
8
1343
by: Larry Bates | last post by:
I have a project that I wanted to solicit some advice on from this group. I have millions of pages of scanned documents with each page in and individual .JPG file. When the documents were scanned the people that did the scanning put a colored (hot pink) separator page between the individual documents. I was wondering if there was any way to utilize PIL to scan through the individual files, look at some small section on the page, and...
3
9040
by: Frank Rizzo | last post by:
I am trying to do some monitoring of some PerfMon counters and have a question. Does PerfMon figure out the Minimum, Maximum, Average values for each counter? Or are those values part of the performance monitoring subsystem and can be accessed via the System.Diagnostics.PerformanceCounter object. I haven't found an obvious way to get to the Minimum, Maximum, Average values for a counter. Thanks.
1
2062
by: Elaine121 | last post by:
Hi i'm writing a program where you have to determine the smallest, number of distinctions and the average from an array of values. in my test class i get an error that says cannot find symbol - constructer IntValues() here is my program: public class IntValuesTest { public static void main(String args) { int valueNum = {45, 84, 56, 79, 63, 92, 76, 54, 61, 72};
10
9038
by: Toby Gallier | last post by:
Hello! I have a form that is calculating averages as follows: " =(NZ()+Nz()+Nz())/3 " However I need to now adjust for null values , so for example if value2 is null I would then need to base my average on just 2 values instead of 3 i am currently using in my string. How can i have the form update the "3" based on the number of values that are populated?
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10327
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10151
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8973
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.