473,804 Members | 2,287 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Date/Time Average

I have a table with help desk ticketing information. There is a
Date/Time open, Date/Time closed field both formatted as: MM/DD/YYYY
hh:nn:ss

I need to calculate the difference between these two times and then
calculate the average of the difference. How do I go about this???

Help is much appreciated...

Shelley

Sep 18 '06 #1
4 6361
sbowman wrote:
I have a table with help desk ticketing information. There is a
Date/Time open, Date/Time closed field both formatted as: MM/DD/YYYY
hh:nn:ss

I need to calculate the difference between these two times and then
calculate the average of the difference. How do I go about this???

Help is much appreciated...

Shelley
Try:

tblHelpTickets
HTID AutoNumber
TicketOpen Date/Time mm/dd/yyyy hh:nn:ss
TicketClose Date/Time mm/dd/yyyy hh:nn:ss

HTID TicketOpen TicketClose
1 09/18/2006 15:00:00 9/18/2006 15:01:03
2 09/18/2006 15:00:04 Null
3 09/18/2006 15:00:07 9/18/2006 15:05:07

qryAvgSeconds:
SELECT Avg(DateDiff("s ", TicketOpen, TicketClose)) As AvgSeconds FROM
tblHelpTickets;

!qryAvgSeconds:
AvgSeconds
181.5

When TicketClose is Null, DateDiff returns Null and the Avg function
will automatically exclude Nulls from the computation.

James A. Fortune
CD********@Fort uneJames.com

Sep 18 '06 #2
After i get the avg in seconds, how do i convert back to dd:hh:nn:ss?

Sep 18 '06 #3
Hi Shelly,

Open up a new query in design view and click Close on the Show Tables
dialog. Unerneath the File menu (top left corner of window) You will
see a dropdown button titled SQL. Just click it to get into the Sql
window. In here you can add the following sql - (change the names of
the fields and the table in the subquery to your actual field/table
names) and then run the query

Select Avg(diff) As diffAvg From
(Select DateDiff("s", dateOpen, dateClose) Ad diff
From tblworkTickets) As t1;

I am using a subqery to get the difference of the open and close dates
in seconds (you can change that to minutes and so on) using the DateDiff
function (you can find more info in the help files on DateDiff
function). This subquery produces a list of numbers which are the
differences of the open/close dates in seconds.

Select DateDiff("s", dateOpen, dateClose) Ad diff
From tblworkTickets

This query is the equivalent of a table. I surround this query with
parentheses which makes it a subquery and I have to give it a name = I
call it t1 for simplicity.

The outer query then averages that list of numbers contained in t1 using
the AVG function. If you want this result in minutes just change the
"s" in

DateDiff("s", dateOpen, dateClose)

to an "n" ---

DateDiff("n", dateOPen, dateClose)

Note: Access will automatically (usually) add square brackets around
the field names after you run the query. This won't affect anything.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Sep 18 '06 #4
sbowman wrote:
After i get the avg in seconds, how do i convert back to dd:hh:nn:ss?
Hi Shelley,

Using the ideas from the following thread:

http://groups.google.com/group/comp....09026f870fd8fd

I came up with the following revised query (barely tested):

SELECT Avg(DateDiff("s ",TicketOpen,Ti cketClose)) AS AvgSeconds,
SecondsToElapse dTime([AvgSeconds]) AS AvgDuration FROM tblHelpTickets;

AvgSeconds AvgDuration
181.5 00:00:03:01.50

using:

'-----Begin Module Code-------
Type ElapsedTime
Days As Integer
Hours As Integer
Minutes As Integer
Seconds As Double
End Type

Public Function FormatElapsedTi me(theTime As ElapsedTime) As String
FormatElapsedTi me = Format(theTime. Days, "00") & ":" &
Format(theTime. Hours, "00") & ":" & Format(theTime. Minutes, "00") & ":"
& Format(theTime. Seconds, "00.00")
End Function

Public Function SecondsToElapse dTime(dblSecond sElapsed As Double) As
String
Dim AnElapsedTime As ElapsedTime

AnElapsedTime.D ays = dblSecondsElaps ed \ (3600# * 24)
AnElapsedTime.H ours = (dblSecondsElap sed \ 3600) Mod 24
AnElapsedTime.M inutes = (dblSecondsElap sed \ 60) Mod 60
AnElapsedTime.S econds = dblSecondsElaps ed - 60 * Int(dblSecondsE lapsed
/ 60)
SecondsToElapse dTime = FormatElapsedTi me(AnElapsedTim e)
End Function
'-------End Module Code-------

But, from an ADH excerpt on MSDN:

"Test 6: use Mid$ rather than concatenation
The often overlooked Mid$ statement allows you to insert text
substrings into other text values. For example, if you used the
following code:

Dim strValue As String
strValue = "I like you"

Mid$(strValue, 3, 4) = "love"
Debug.Print strValue

strValue would contain "I love you" once you had finished. The
alternative would be to write code like this:

Dim strValue As String
strValue = "I like you"
strValue = Left$(strValue, 2) & "love" & Mid$(strValue, 7)
Debug.Print strValue

The first alternative is significantly faster than the second. In our
test case, either concatenating a series of X characters to build an
output string, or using the Mid$ statement to replace each character in
the output string with X, the faster version (using Mid$) took only 50
percent as long as the slower version. Of course, the relative timings
might change depending on the action you were taking. In general,
concatenation should be avoided in VBA. (See Test6a/b for the full test
procedures.)"

So the FormatElapsedTi me function should be changed, maybe using
something like

strTemp = "dd:hh:nn:ss.ss "

along with a few calls to the Mid$ function. I haven't tried this yet.

James A. Fortune
CD********@Fort uneJames.com

Sep 18 '06 #5

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

Similar topics

28
742
by: Steve | last post by:
Hi all How would I find out the average date when given a bunch of dates? For example, I want to find the average length in time from the following dates: ---------------------------------------------------- Start Date End Date 01/01/2004 12:50pm 02/01/2004 18:40pm 02/01/2004 13:40pm 02/01/2004 13:57pm 02/01/2004 14:30pm 02/01/2004 19:50pm
8
3032
by: Dennis M. Marks | last post by:
What is the maximum valid date range for the date(yyyy,mm,dd) function. -- Dennis M. Marks http://www.dcs-chico.com/~denmarks/ Replace domain.invalid with dcsi.net -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
17
2521
by: clintonG | last post by:
When the following code is run on Sat Dec 25 2004 19:54:18 GMT-0600 (Central Standard Time) var today = new Date(); var GMTDate = today.toGMTString(); document.write("GMTDate: " + GMTDate); The code returns: Sun, 26 Dec 2004 19:54:18 GMT (the next day after the code was actually run)
8
7863
by: Marcel Linnenfelser | last post by:
Hi there, we try to emulate the AVG function for use with type DATE. How can we convert DATE or TIMESTAMP to milliseconds? Or how can we get the average of DATEs directly?? thx, kind regards
2
3653
by: Mary | last post by:
I am trying to develop a query which will determine the average costs using a rolling average of the past 12 months of data. In other words, if I entered the Ship Month of January and the Ship Year of 2004, I would want that month plus the preceding 11 months of data to determine an average cost. How can that criteria be entered in a query so that each month I can get the most current 12 months of data to determine the average costs? ...
6
14402
by: KoRnDragon | last post by:
I know about getlastmod() but is there one for created date? If not is there some other way of getting the created date of a file?
0
363
by: sbowman | last post by:
I have a table with help desk ticketing information. There is a Date/Time open, Date/Time closed field both formatted as: MM/DD/YYYY hh:nn:ss I need to calculate the difference between these two times and then calculate the average of the difference. How do I go about this??? Help is much appreciated... Shelley
44
10243
by: user | last post by:
Hi, Let's say I have 2 dates in the b/m format: Date 1 and date 2 How do I check whether Date2 is later than Date 1? Date1. 21-Nov-2006 09:00:00 PM
1
3536
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 WindDir WindDirRads V
0
9712
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
10595
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
9171
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...
1
7634
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 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...
0
6862
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
5530
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...
1
4308
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
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
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.