473,662 Members | 2,588 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sum Time Function.

Hi Group (fairly limited knowledge of Access and almost none of Access
VBA. Using Access 2003).

I need to sum time, I've found through the groups archive an sql
extract that led me to this

SELECT Format(Sum(Tabl e2.time),"Short Time") AS SumOftime
FROM Table2;

Which works fine but the article also said I would need a Function to
deal with sum when it exceeded 24.

I think I might of found it but could do with a direct explanation or
a little help with what I found
Function GetElapsedTime( interval)
Dim totalhours As Long, totalminutes As Long, totalseconds As
Long
Dim days As Long, hours As Long, Minutes As Long, Seconds As
Long
days = Int(CSng(interv al))
totalhours = Int(CSng(interv al * 24))
totalminutes = Int(CSng(interv al * 1440))
totalseconds = Int(CSng(interv al * 86400))
hours = totalhours Mod 24
Minutes = totalminutes Mod 60
Seconds = totalseconds Mod 60
GetElapsedTime = days & " Days " & hours & " Hours " &
Many thanks in anticipation

Don

Nov 8 '07 #1
2 7593
On Nov 8, 6:38 am, dwasb...@gmail. com wrote:
Hi Group (fairly limited knowledge of Access and almost none of Access
VBA. Using Access 2003).

I need to sum time, I've found through the groups archive an sql
extract that led me to this

SELECT Format(Sum(Tabl e2.time),"Short Time") AS SumOftime
FROM Table2;

Which works fine but the article also said I would need a Function to
deal with sum when it exceeded 24.

I think I might of found it but could do with a direct explanation or
a little help with what I found

Function GetElapsedTime( interval)
Dim totalhours As Long, totalminutes As Long, totalseconds As
Long
Dim days As Long, hours As Long, Minutes As Long, Seconds As
Long

days = Int(CSng(interv al))
totalhours = Int(CSng(interv al * 24))
totalminutes = Int(CSng(interv al * 1440))
totalseconds = Int(CSng(interv al * 86400))
hours = totalhours Mod 24
Minutes = totalminutes Mod 60
Seconds = totalseconds Mod 60

GetElapsedTime = days & " Days " & hours & " Hours " &

Many thanks in anticipation

Don
The 'interval' consists of a nonnegative whole number representing
days followed by a decimal part representing the fraction of a day.
Think of 'interval' as a large barrel of liquid with marks on the
inside like those on the outside of a measuring glass for a day, an
hour, a minute and a second. The number in 'interval' corresponds to
how much liquid is in the barrel. Also assume that you have some
barrels labeled 'days' (a large barrel), 'totalhours', 'totalminutes'
and 'totalseconds'. You also have some measuring containers labeled
'day', 'hour', 'minute' and 'second'. You are to perform the
following procedure:

As long as you are not below the 'day' mark on the inside of the
'interval' barrel, measure out enough liquid to fill the measuring
container labeled 'day' and dump the liquid into the barrel labeled
'days'. Record how many times you had to do that. Now pour all the
liquid in 'days' back into 'interval'! Then repeat the process for
'totalhours', 'totalminutes' and 'totalseconds' using the
corresponding measuring marks and containers. Note: I prefer using a
method that doesn't force me to pour the contents back into the
original container. Since we're starting with days at the top (no
months), the tally for 'days' will be the number of days. The tally
for 'totalhours' is possibly too high because any hours included in
the tally for 'days' have been counted twice due to the liquid being
poured back into the original container. Taking the 'totalhours'
tally Mod 24 removes the hours that would be counted twice. The tally
for 'totalminutes' may also be too high by being counted in either the
'days' tally or in the 'totalhours' tally. Taking the tally for
'totalminutes' Mod 60 eliminates any minutes counted in the 'days'
tally along with any minutes counted in the 'totalhours' tally.
Similar reasoning applies to 'totalseconds'.

Methods that don't refill the initial barrel have more built-in
protection against an error of one second becoming an error of 59
seconds should a floating-point approximation somehow cause 'interval'
to produce one less 'totalminutes'. That should not actually happen
because 86400 is a relatively small integral multiple of 1440 causing
a total number of minutes barely under an integer to correspond to a
total number of seconds barely under an integer. I.e., if you get 59
'totalseconds' instead of 0 seconds due to an internal floating-point
approximation, you will also get one less 'totalminutes', keeping the
result within a second of the actual value.

In short, the function looks like it will work, assuming the last line
is fixed, to within a second provided 'interval' doesn't go beyond
about 24855 days (2147483647 {sec} / 86400 {sec/day}), i.e. about 68
years, but the technique is, IMO, slightly more clever than robust.
I'd almost say that the author got lucky concerning the floating-point
approximation case.

After writing the above I found the following note, after a Google
search, in:

http://groups.google.com/group/comp....22f0861bbe4d78

'----------------------------------------------
Function GetElapsedTime( dblInterval As Double) As String
'Returns a formatted string showing elapsed time
' dblInterval may be the difference between any two VBA dates.
' The sum or difference between two VBA dates returns an double
number,
' where the integer portion is the number of days and the fractional
' portion is the part of one day.
' Function returns correct elpased time up to two billion seconds or
' approximately 68 years. Causes runtime error for ages over 68
years.

'Source:
'INF: Functions for Calculating and Displaying Date/Time Values
'Article ID: Q88657
'Copyright (c) Microsoft Corporation. 1997.
'Variants of this function also appear in Microsoft's NeatCode.mdb
and
'in Getz's VBA Developer's Handbook as function FormatInterval.

Note that my solution for elapsed time in:

http://groups.google.com/group/micro...7e101c5176ebd8

is also limited to about 68 years, but the OP was talking about a
running contest :-). I note in passing that the choice of a Long data
type input conveniently obviated any floating-point approximation
considerations and allowed me to get away with a little bit of barrel
refilling. Maybe I got lucky also.

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

Nov 9 '07 #2
James

Very sorry for delay in replying. Thank you for taking the time to
reply in such detail. I've not got it working as yet (not been well)
but will be checking out your advice and link.

Many thanks again.

Don

Nov 14 '07 #3

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

Similar topics

2
5210
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much appreciated. TIA
6
12913
by: David Graham | last post by:
Hi I have asked this question in alt.php as the time() function as used in setcookie belongs to php - or does it belong equally in the javascript camp - bit confused about that. Anyway, can anyone here put me straight on the following: I had a look at the time() function came across this: "To clarify, it seems this function returns the time of the computer's clock and does not do any timezone adjustments to return GMT, so you are...
17
3120
by: newbiecpp | last post by:
I have hard time to understand run-time environment. Let assume that I have a program that has a simple variable alpha. When this variable is statically allocated, the compiler can use the absolute address of alpha to access to it. What confuses me is that when the variable is dynamically allocated, how does the compiler implement it? We know the address of the variable until run-time. During the compilation, how can we access to the...
17
2196
by: Razzel | last post by:
I created this as a test: #include <time.h> main(){ printf(X1: %s\n", putim()); printf(X2: %s\n", putim()); } putim() { time_t t; time(&t); return(ctime(&t));
5
3101
by: Sinan Nalkaya | last post by:
hello, i need a function like that, wait 5 seconds: (during wait) do the function but function waits for keyboard input so if you dont enter any it waits forever. i tried time.sleep() but when i used time.sleep in while, the function in while never executed. then i found something about Timer but couldnt realize any algorithm in my mind.
3
2027
by: cj | last post by:
If I want to check to see if it's after "11:36 pm" what would I write? I'm sure it's easy but I'm getting tired of having to work with dates and times. Sometimes I just want time or date. And to be able to do comparisons on them.
6
12542
by: Luvin lunch | last post by:
Hi, I'm new to access and am very wary of dates as I have limited experience in their manipulation and I know if they're not done properly things can turn ugly quickly. I would like to use a calendar control to allow my users to enter a date but I need them to enter a time as well. It doesn't look like the calendar control will allow times to be entered so I was thinking of having two text boxes. One text box would contain the date...
9
8287
by: Ron Adam | last post by:
I'm having some cross platform issues with timing loops. It seems time.time is better for some computers/platforms and time.clock others, but it's not always clear which, so I came up with the following to try to determine which. import time # Determine if time.time is better than time.clock # The one with better resolution should be lower.
0
16490
yasirmturk
by: yasirmturk | last post by:
Standard Date and Time Functions The essential date and time functions that every SQL Server database should have to ensure that you can easily manipulate dates and times without the need for any formatting considerations at all. They are simple, easy, and brief and you should use them any time you need to incorporate any date literals or date math in your T-SQL code. create function DateOnly(@DateTime DateTime) -- Returns @DateTime...
1
2327
by: nigelesquire | last post by:
I am in need of your assistance. I have a page with multiple unixtime stamps and I need to display them in readable time and date with the user's time zone. Below is the code. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
0
8432
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
8857
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
8764
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
7367
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
6186
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
5654
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
4180
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...
2
1993
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1752
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.