473,854 Members | 1,931 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 1319
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**********@d iscussions.micr osoft.com> wrote in message news:5D******** *************** ***********@mic rosoft.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.Tab les.Add(New DataTable)
pathDataSet.Tab les(3).Columns. Add(New DataColumn("tas k_number",
System.Type.Get Type("System.In t32")))
pathDataSet.Tab les(3).Columns. Add(New DataColumn("tas k_date",
System.Type.Get Type("System.Da teTime")))
For i = 0 To pathDataSet.Tab les(2).Rows.Cou nt - 1
If previousTask = pathDataSet.Tab les(2).Rows(i). Item("task_numb er") Then
total += CType(pathDataS et.Tables(0).Ro ws(i).Item("tas k_date"),
Date).ToOADate
x += 1
Else
average = Date.FromOADate (total / x)
pathDataSet.Tab les(3).Rows.Add (pathDataSet.Ta bles(3).NewRow)
pathDataSet.Tab les(3).Rows(y). Item("task_numb er") = previousTask
pathDataSet.Tab les(3).Rows(y). Item("task_date ") = average
y += 1
total = 0
x = 1
End If
previousTask = pathDataSet.Tab les(2).Rows(i). Item("task_numb er")
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**********@d iscussions.micr osoft.com> wrote in message news:5D******** *************** ***********@mic rosoft.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.Tab les.Add(New DataTable)
pathDataSet.Tab les(3).Columns. Add(New DataColumn("tas k_number",
System.Type.Get Type("System.In t32")))
pathDataSet.Tab les(3).Columns. Add(New DataColumn("tas k_date",
System.Type.Get Type("System.Da teTime")))
For i = 0 To pathDataSet.Tab les(2).Rows.Cou nt - 1
If previousTask = pathDataSet.Tab les(2).Rows(i). Item("task_numb er") Then
total += CType(pathDataS et.Tables(0).Ro ws(i).Item("tas k_date"),
Date).ToOADate
x += 1
Else
average = Date.FromOADate (total / x)
pathDataSet.Tab les(3).Rows.Add (pathDataSet.Ta bles(3).NewRow)
pathDataSet.Tab les(3).Rows(y). Item("task_numb er") = previousTask
pathDataSet.Tab les(3).Rows(y). Item("task_date ") = average
y += 1
total = 0
x = 1
End If
previousTask = pathDataSet.Tab les(2).Rows(i). Item("task_numb er")
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**********@d iscussions.micr osoft.com> wrote in message news:5D******** *************** ***********@mic rosoft.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.Tab les.Add(New DataTable)
pathDataSet.Tab les(3).Columns. Add(New DataColumn("tas k_number",
System.Type.Get Type("System.In t32")))
pathDataSet.Tab les(3).Columns. Add(New DataColumn("tas k_date",
System.Type.Get Type("System.Da teTime")))
For i = 0 To pathDataSet.Tab les(2).Rows.Cou nt - 1
If previousTask = pathDataSet.Tab les(2).Rows(i). Item("task_numb er") Then
total += CType(pathDataS et.Tables(0).Ro ws(i).Item("tas k_date"),
Date).ToOADate
x += 1
Else
average = Date.FromOADate (total / x)
pathDataSet.Tab les(3).Rows.Add (pathDataSet.Ta bles(3).NewRow)
pathDataSet.Tab les(3).Rows(y). Item("task_numb er") = previousTask
pathDataSet.Tab les(3).Rows(y). Item("task_date ") = average
y += 1
total = 0
x = 1
End If
previousTask = pathDataSet.Tab les(2).Rows(i). Item("task_numb er")
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**********@d iscussions.micr osoft.com> wrote in message news:5D******** *************** ***********@mic rosoft.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
78969
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 <input type="checkbox" name="pet" value="pig"> <br> <select name="dates" multiple> <option value="Monday">Monday</option> <option value="Tuesday">Tuesday</option>
4
5397
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 calculate days, months, and years. This is not for a college course. It's for my own personal genealogy website. I'm stumped about the code. I'm working on it but not making much progress. Is there any free code available anywhere? I know it...
0
8786
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 Append Queries) when the Database is first opened, and then again anytime I invoke the Macro (somehow) after the database is already open. The latter function is useful, because the queries must be rerun every time data is added, deleted, or...
1
2204
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 maybe I even have it set up wrong. I am putting some evaluation forms online. Each form/table is different, apart from the first 10 questions which are the exact same
1
2247
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 the number of days and the counts. I have created the corresponding report to show the sum and verages. But I don't know how to make them print on a main report that will display the information of multiple status since I have to enter multiple...
5
50589
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'), and so on. This is the thought: //person
4
3016
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 to prompt for a begin date and an end date.This returns a report with a result set of all records that fall within the dates specified. The report has 3 sub reports as well, which also uses the date criteria from the form. When I enter my begin and...
1
1704
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 number averaging program. But when I run it in Eclipse or the command line and I enter: 1 3 5.5 It says the average is 3.1666666666666665 when it should be 3.1666666666666667. I checked and am positive it is dividing the sum by 3. What do I...
2
9224
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 timestamped using the UNIX epoch timestamp (if needed I could convert this to a MySQL timestamp). When viewing the data in just one day, it is okay to show all rows, but we run into a problem with load times when we go past say a week... (at 1440 rows per...
0
11023
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
10672
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...
1
10740
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10362
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
9509
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
7076
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5738
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
5936
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4550
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

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.