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). 4 1311
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).
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).
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).
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). This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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>
|
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...
|
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...
|
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
|
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...
| |
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
|
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...
|
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...
|
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...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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...
| |
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,...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |