473,511 Members | 16,830 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Averaging multiple dates

I have a query that returns multiple dates and I want to find the average
date... How can I do this?

I tried to use the ToOADate() to get the total of the dates as a double,
then divide by the number of dates and use FromOADate() to get back to a
date, but it does not produce the desired results (as I expected, but still
was hopefull it might).
Nov 19 '05 #1
4 1297
Can you give me an example with a few dates, and tell me what your "desired" results would be? Using ToOADate/FromOADate seems like a really good idea to me, so I'm wondering what problem you were having with it.

--Michael

"Matt Hamilton" <Ma**********@discussions.microsoft.com> wrote in message news:5D**********************************@microsof t.com...
I have a query that returns multiple dates and I want to find the average
date... How can I do this?

I tried to use the ToOADate() to get the total of the dates as a double,
then divide by the number of dates and use FromOADate() to get back to a
date, but it does not produce the desired results (as I expected, but still
was hopefull it might).

Nov 19 '05 #2
10-29-2004
11-03-2004
11-03-2004
11-01-2004

I expect something like 11-01-2004 for the average of these dates. When I
use the method we are talking about, I get 11-19-1983 as the average... Here
is the code I am using:

Dim previousTask, x, y As Integer
previousTask = 1
x = 1
y = 0
Dim total As Long
total = 0
Dim average As Date
pathDataSet.Tables.Add(New DataTable)
pathDataSet.Tables(3).Columns.Add(New DataColumn("task_number",
System.Type.GetType("System.Int32")))
pathDataSet.Tables(3).Columns.Add(New DataColumn("task_date",
System.Type.GetType("System.DateTime")))
For i = 0 To pathDataSet.Tables(2).Rows.Count - 1
If previousTask = pathDataSet.Tables(2).Rows(i).Item("task_number") Then
total += CType(pathDataSet.Tables(0).Rows(i).Item("task_dat e"),
Date).ToOADate
x += 1
Else
average = Date.FromOADate(total / x)
pathDataSet.Tables(3).Rows.Add(pathDataSet.Tables( 3).NewRow)
pathDataSet.Tables(3).Rows(y).Item("task_number") = previousTask
pathDataSet.Tables(3).Rows(y).Item("task_date") = average
y += 1
total = 0
x = 1
End If
previousTask = pathDataSet.Tables(2).Rows(i).Item("task_number")
Next
"Raterus" wrote:
Can you give me an example with a few dates, and tell me what your "desired" results would be? Using ToOADate/FromOADate seems like a really good idea to me, so I'm wondering what problem you were having with it.

--Michael

"Matt Hamilton" <Ma**********@discussions.microsoft.com> wrote in message news:5D**********************************@microsof t.com...
I have a query that returns multiple dates and I want to find the average
date... How can I do this?

I tried to use the ToOADate() to get the total of the dates as a double,
then divide by the number of dates and use FromOADate() to get back to a
date, but it does not produce the desired results (as I expected, but still
was hopefull it might).

Nov 19 '05 #3
I may be doing something wrong in the code because it appears to work when
using hard-coded values. I will update this thread when I resolve or find
that I cannot resolve this issue. Thanks!

"Matt Hamilton" wrote:
10-29-2004
11-03-2004
11-03-2004
11-01-2004

I expect something like 11-01-2004 for the average of these dates. When I
use the method we are talking about, I get 11-19-1983 as the average... Here
is the code I am using:

Dim previousTask, x, y As Integer
previousTask = 1
x = 1
y = 0
Dim total As Long
total = 0
Dim average As Date
pathDataSet.Tables.Add(New DataTable)
pathDataSet.Tables(3).Columns.Add(New DataColumn("task_number",
System.Type.GetType("System.Int32")))
pathDataSet.Tables(3).Columns.Add(New DataColumn("task_date",
System.Type.GetType("System.DateTime")))
For i = 0 To pathDataSet.Tables(2).Rows.Count - 1
If previousTask = pathDataSet.Tables(2).Rows(i).Item("task_number") Then
total += CType(pathDataSet.Tables(0).Rows(i).Item("task_dat e"),
Date).ToOADate
x += 1
Else
average = Date.FromOADate(total / x)
pathDataSet.Tables(3).Rows.Add(pathDataSet.Tables( 3).NewRow)
pathDataSet.Tables(3).Rows(y).Item("task_number") = previousTask
pathDataSet.Tables(3).Rows(y).Item("task_date") = average
y += 1
total = 0
x = 1
End If
previousTask = pathDataSet.Tables(2).Rows(i).Item("task_number")
Next
"Raterus" wrote:
Can you give me an example with a few dates, and tell me what your "desired" results would be? Using ToOADate/FromOADate seems like a really good idea to me, so I'm wondering what problem you were having with it.

--Michael

"Matt Hamilton" <Ma**********@discussions.microsoft.com> wrote in message news:5D**********************************@microsof t.com...
I have a query that returns multiple dates and I want to find the average
date... How can I do this?

I tried to use the ToOADate() to get the total of the dates as a double,
then divide by the number of dates and use FromOADate() to get back to a
date, but it does not produce the desired results (as I expected, but still
was hopefull it might).

Nov 19 '05 #4
This method does work, but I had some errors in the code example. Sorry!

"Matt Hamilton" wrote:
10-29-2004
11-03-2004
11-03-2004
11-01-2004

I expect something like 11-01-2004 for the average of these dates. When I
use the method we are talking about, I get 11-19-1983 as the average... Here
is the code I am using:

Dim previousTask, x, y As Integer
previousTask = 1
x = 1
y = 0
Dim total As Long
total = 0
Dim average As Date
pathDataSet.Tables.Add(New DataTable)
pathDataSet.Tables(3).Columns.Add(New DataColumn("task_number",
System.Type.GetType("System.Int32")))
pathDataSet.Tables(3).Columns.Add(New DataColumn("task_date",
System.Type.GetType("System.DateTime")))
For i = 0 To pathDataSet.Tables(2).Rows.Count - 1
If previousTask = pathDataSet.Tables(2).Rows(i).Item("task_number") Then
total += CType(pathDataSet.Tables(0).Rows(i).Item("task_dat e"),
Date).ToOADate
x += 1
Else
average = Date.FromOADate(total / x)
pathDataSet.Tables(3).Rows.Add(pathDataSet.Tables( 3).NewRow)
pathDataSet.Tables(3).Rows(y).Item("task_number") = previousTask
pathDataSet.Tables(3).Rows(y).Item("task_date") = average
y += 1
total = 0
x = 1
End If
previousTask = pathDataSet.Tables(2).Rows(i).Item("task_number")
Next
"Raterus" wrote:
Can you give me an example with a few dates, and tell me what your "desired" results would be? Using ToOADate/FromOADate seems like a really good idea to me, so I'm wondering what problem you were having with it.

--Michael

"Matt Hamilton" <Ma**********@discussions.microsoft.com> wrote in message news:5D**********************************@microsof t.com...
I have a query that returns multiple dates and I want to find the average
date... How can I do this?

I tried to use the ToOADate() to get the total of the dates as a double,
then divide by the number of dates and use FromOADate() to get back to a
date, but it does not produce the desired results (as I expected, but still
was hopefull it might).

Nov 19 '05 #5

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

Similar topics

3
78675
by: RC | last post by:
I am try test a simple HTML form with PHP <form method=POST action="testing.php"> Cat <input type="checkbox" name="pet" value="cat"> Dog <input type="checkbox" name="pet" value="dog"> Pig...
4
5345
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
0
8751
by: MHenry | last post by:
Hi, I know virtually nothing about creating Macros in Access. I would appreciate some help in creating a Macro or Macros that automatically run(s) 14 Queries (three Make Table Queries, and 11...
1
2189
by: Rotten Spice | last post by:
Hello all, I am still pretty new to Access but I do have a grasp on some basic functions. I am having a problem with averaging and I think I'm trying to do something a little too complex and...
1
2229
by: josecruz | last post by:
I have to create a summary report that will provide counts and # average of days for multiple "Status" by entering different dates for every criteria. I have created several queries that calculates...
5
50551
by: jorgedelgadolopez | last post by:
Hi all, I am using the xpathnavigator evaluate function on .net (xpath 1 right?). Now I need to expand the code to do multiple contains, compare dates (such as 'before', 'between' and 'after'),...
4
3001
by: dawanwan | last post by:
I built a database at my job for tracking and reporting debt records. I am very new at using Access and have basically trained myself. Here's my problem: I created a parameter query using a form...
1
1690
by: Kid Programmer | last post by:
Hello guys. Whenever I am learning a new programming language I like to learn the basics (variables, loops, conditionals etc) by writing a program that will calculate averages. I wrote a simple...
2
9200
bergy
by: bergy | last post by:
Background: We are collecting data and pushing it to MySQL at various intervals. Sometimes it may be every minute, other times every 15 minutes, and all ranges in between. This data is...
0
7138
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
7423
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...
1
7081
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
5668
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
4737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3213
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1576
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 ...
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
447
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...

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.