473,396 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how can I sum stop watch time

Hi all ..
I have a stopwatch form in Access that records results in a table and I wants to sum the time in this table as it is 00:00:00:00

Thanks inadvance
Dec 23 '15 #1
23 2035
Rabbit
12,516 Expert Mod 8TB
I don't understand your question. If the time is always 0, then 0 + 0 = 0. There's no point in adding it up.
Dec 23 '15 #2
I wanted to upload the form here and I already archived it into a rar file but it gave me error when uploading ...
about the time it is hh:mm:ss:ms

I start time then when I press reset button the time is recorded automatically into the table I want to "sum" this time
Dec 23 '15 #3
the time is not alwas 0 this is the time format 00:00:00:00 that I want to sum
Dec 23 '15 #4
Rabbit
12,516 Expert Mod 8TB
First of all, Access doesn't have a data type that is purely time. It always has a date component. The display format might only display the time but that doesn't mean the date part of the field isn't there, it's just not showing it.

Second, it doesn't make sense to add date time values. What would the result of Christmas + New Years = ? Really, what you want to add is a date time interval. And you have to decide what interval that is.

To get the interval from a date time data type, you can use the DateDiff() function. So if I wanted to calculate the number of minutes, I could do DATEDIFF(mm, 0, TimerField). Once I have converted the date time field into a time interval, then I can use the SUM() on it.
Dec 23 '15 #5
Is there any way to send you the file ??
Dec 23 '15 #6
here is a link for the file
http://www.4shared.com/rar/SSlhWa7Yba/stopwatch3.html
Dec 23 '15 #7
Rabbit
12,516 Expert Mod 8TB
Sorry, I don't download files from people I don't know.
Dec 23 '15 #8
zmbd
5,501 Expert Mod 4TB
Personally, I would look at storing your time as elapsed milliseconds. This would be a simple integer data type.

You can then convert the number of seconds to HH:MM:ss:ms
Dec 23 '15 #9
so rabbit I sent you the access file to check it .. or tell me the way that you can help me with
Dec 23 '15 #10
zmbd .. did you check the file ??
it is almost the same idea but I cannot sum that time or convert I need help with that as I am a little bit new to access DB and functions... thanks alot for response
Dec 23 '15 #11
zmbd
5,501 Expert Mod 4TB
Provided the results are in a table, you should be able to create an aggregate query, as shown here Sum data by using a query once you have the sum, you can then format as needed.

You can also do the same within VBA; however, a query would be faster.


msamir12: Please understand, many of us cannot or will not d/l un-requested attachments. In my case, such d/l are prohibited by my ITSec staff. For many others, it is part of "safe computing/best practices" not to d/l such files. A practical example as to why can be found here http://bytes.com/topic/access/answer...l-ms-products. this unfourtunate Member opened a file from a trusted source and is now haveing all sorts of issues!
Dec 24 '15 #12
Thanks zmbd I appretiate it and evaluate your efforts now I understand it very well I just wanted some one to check the case from the source file to give openion depending on case study that is it .. thanks once again for your help so as "Rabbit" as well ..
thank you guys
Dec 24 '15 #13
NeoPa
32,556 Expert Mod 16PB
Let me just clarify. I suspect the actual format required is hh:mm:ss.ms. hh:mm:ss:ms makes little sense to me and I've never seen fractions of a second shown that way.

That said, always remember that what is shown (IE. The format.) is only relevant to data being viewed and any format should only ever be applied as the very last thing before displaying it. Data should always be worked on in its native format.

Although Rabbit is correct when he states that adding date/time values together produces results that are meaningless, this is only true for timestamp values. IE. Those representing a specific point in time. Subtracting one timestamp from another can make sense and results in a duration. Durations can sensibly be summed together and I suspect this is what you're talking about here. A duration is also a time (period) and can be stored as a Date/Time just as a timestamp value can. Bear in mind though, that the formatting in Office only really handles timestamps fully. This should only ever be a problem when dealing with durations, or sums of durations, that exceed twenty-four hours though. At least that is true unless any unit greater than hours is involved in the format, such as d, mm, yyyy, etc.

So, assuming for now that this won't be the case, you can store your durations in a Date/Time field. Be careful to avoid confusing these values with timestamp values of course.

Summing these values together is just as straightforward as summing values of numeric types together.
Dec 24 '15 #14
hvsummer
215 128KB
@msamir12:

One way that you allow you to sum those data, that is split hh:mm:ss.ms in each field, hh in integer field, mm in integer field, etc...

then set the sum condition, like this:
mm > 60 -> hh = hh + int(mm/60)
ss > 60 -> mm = mm + int(ss/60)
ms > 100 -> ss = ss + int(ms/100)
Dec 24 '15 #15
I need a fast solution as I am new in here and in using access
Dec 24 '15 #16
@hvsummer I think this is the nearest to what I need but I already have the stopwatch running like that and I already saved the data into a table but the thing here is how to sum this data as it is like that
00:00:00:57
00:00:10:46
this is a live data from the table I think the problem is in milliseconds if any one can help me with a code or to explain the way to do this I will be very Grateful to him thank you guys
Dec 25 '15 #17
zmbd
5,501 Expert Mod 4TB
msamir12:
Please post the script you are using to run the stop-watch, this will tell us more about your data.

Please format the script with the [CODE/] when you post it.
Dec 25 '15 #18
This is in the start/stop button :
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnStartStop_Click()
  2.  
  3.  If Me.TimerInterval = 0 Then
  4.       StartTickCount = GetTickCount()
  5.       Me.TimerInterval = 15
  6.       Me!btnStartStop.Caption = "Stop"
  7.       Me!btnReset.Enabled = False
  8.    Else
  9.       TotalElapsedMilliSec = TotalElapsedMilliSec + _
  10.          (GetTickCount() - StartTickCount)
  11.       Me.TimerInterval = 0
  12.       Me!btnStartStop.Caption = "Start"
  13.       Me!btnReset.Enabled = True
  14.    End If
  15.  
  16. End Sub
And this code is in the reset button :
Expand|Select|Wrap|Line Numbers
  1.   DoCmd.RunCommand acCmdSaveRecord
  2.     DoCmd.GoToRecord , , acNewRec
  3.  
  4. TotalElapsedMilliSec = 0
  5.    Me!ElapsedTime = "00:00:00:00"
  6.  
The OnOpen form code :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2.  
  3. TotalElapsedMilliSec = 0
  4.  
  5. End Sub
The on timer code :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Timer()
  2.  
  3.    Dim Hours As String
  4.    Dim Minutes As String
  5.    Dim Seconds As String
  6.    Dim MilliSec As String
  7.    Dim Msg As String
  8.    Dim ElapsedMilliSec As Long
  9.  
  10.    ElapsedMilliSec = (GetTickCount() - StartTickCount) + _
  11.       TotalElapsedMilliSec
  12.  
  13.    Hours = Format((ElapsedMilliSec \ 3600000), "00")
  14.    Minutes = Format((ElapsedMilliSec \ 60000) Mod 60, "00")
  15.    Seconds = Format((ElapsedMilliSec \ 1000) Mod 60, "00")
  16.    MilliSec = Format((ElapsedMilliSec Mod 1000) \ 10, "00")
  17.  
  18.    Me!ElapsedTime = Hours & ":" & Minutes & ":" & Seconds & ":" _
  19.       & MilliSec
  20.  
  21. End Sub
Also I have a problem that the time is recorded in a text field, not date/time field, in the table.
Dec 25 '15 #19
hvsummer
215 128KB
@msamir12:
Expand|Select|Wrap|Line Numbers
  1. Me!ElapsedTime = Hours & ":" & Minutes & ":" & Seconds & ":" _
  2.       & MilliSec
this part of code join all 4 field into 1 (Me!ElapsedTime)
if you change that part of code into this
Expand|Select|Wrap|Line Numbers
  1. Me!Hours = Hours
  2. Me!Minutes = minutes
  3. Me!Seconds = seconds
  4. Me!millisec = millisec
or
Expand|Select|Wrap|Line Numbers
  1. public function getTimeData(Type as integer)
  2. TempArray = split(Me!ElapsedTime, ":")
  3. getTimeData = TempArray(Type)
  4. end function
  5.  
then you can sum those field like I said in my previous comment.
(with priority ms -> sec -> minutes -> hours)
ofc you have to use vba to sum (make an function or sub).
we can't sum easily with total query (some what more complex than use vba)
but if you interesting in that, this example can help you
Expand|Select|Wrap|Line Numbers
  1. SELECT 
  2. (Hours + iif(minutes > 60, int(minutes/60), 0) 
  3. + iif(minutes + int(seconds/60) > 60, int((minutes + int(seconds/60))/60), 0) 
  4. + iif(minutes + int(seconds/60) + int(int(ms/100)/60) > 60, int((minutes + int(seconds/60) + int(int(ms/100)/60))/60), 0)) as Hours,
  5.  
  6. iif((minutes + iif(seconds > 60, int(seconds/60), 0)
  7. +iif(seconds + int(ms/100) > 60, int( (seconds + int(ms/100))/60), 0)) > 60 ,int( ((minutes + iif(seconds > 60, int(seconds/60), 0)
  8. +iif(seconds + int(ms/100) > 60, int( (seconds + int(ms/100))/60), 0)))/60) ,(minutes + iif(seconds > 60, int(seconds/60), 0)
  9. +iif(seconds + int(ms/100) > 60, int( (seconds + int(ms/100))/60), 0))) as minutes,
  10.  
  11. iif((seconds + iif(ms > 100, int(ms/100), 0)> 60, int( ((seconds + iif(ms > 100, int(ms/100), 0))/60), (seconds + iif(ms > 100, int(ms/100), 0)) as seconds,
  12.  
  13. iif(ms > 100, int(ms/100), ms) as ms
  14.  
  15. from YourTable
  16.  
Dec 25 '15 #20
NeoPa
32,556 Expert Mod 16PB
msamir12:
Also I have a problem that the time is recorded in a text field, not date/time field, in the table.
I would say this is your major problem. Sure, it's possible to do this using separate numbers, but I really wouldn't recommend that approach as it just makes everything so much more complicated. I suggest you fix that first then the rest should be fairly basic to do. If the value is stored as a basic Date/Time I mean of course. Separating the different elements instead of allowing the system to handle that for you is a recipe for more complicated work and much more probability of error.
Dec 25 '15 #21
hvsummer
215 128KB
@Neopa as you said lets system handle that, I was thinking why he has to save everything in that time format ?
hh:mm:ss.ms ?

@msamir12
you can convert those data into sec (can be 100 sec, 2000 sec, or 100000 sec)

access store time as part of day, so you can convert into sec by multiply 86400

then you will be able to sum those sec (something like sum([ElapsedTime] * 86400)), and convert data back into hh:mm:ss.ms ? all problem will vanish ==
Dec 25 '15 #22
zmbd
5,501 Expert Mod 4TB
my thoughts
+ Declare {TotalElapsedMilliSec} as a form level variable of data-type long

+ In the current table you are strong your times, create a field called [elapsedtime] numeric(long)

+ [elapsedtime] will be the field to start storing the {TotalElapsedMilliSec} value in to the record set.
> Why not a date/time data-type, because the only time you are interested in the HH:MM:SS.ms format appears to be for display. A simple, primitive, data-type eloquently handles the raw data; thus, avoiding some of the "gotchas" of the date/time data-type and you can convert to the textual-human format "on the fly."

+ Take the code that converts {TotalElapsedMilliSec} in to the "HH:MM:SS.ms" convert this to a function. It will be used to format the time for displaying in your queries, forms, and reports. At no time will this format be saved. For example to show the formatted time in the control named "ElapsedTime"
Me!ElapsedTime = fHHMMSSms({TotalElapsedMilliSec})

In a query you could feed the [elapsedtime] to the function, in the GUI-QueryEditor:
HH_MM_SS_ms: fncHHMMSSms([elapsedtime])

Same thought for a calculated control etc...

+ With this arrangement you could then build your aggregate-query against your criteria and summing the [ElapsedTime] field, feeding the results of [Sum_of_ElapsedTime] to the fncHHMMSSms() function if needed for the displayed format.

I suggest starting a new thread if you need in-depth help with the following, you can include a link back to this thread if you need context :)
What to do with the current data?:
The following could be done via SQL and an update_query... I think; however, in this case I also think this to be very messy.

What I would do instead is, in VBA, open a DAO-Recordset against your table.
Move to the first record.
Create code that uses the split() function against the colon to split your data in to the 0-base-array feeding the function the field name you are storing your data.
So long as all of your data is "HH : MM : SS : MS"
then Array(0) with contain your Hours, Array(1)= minutes, etc; however, the values will be string-typecast because your field is text-typecast.

We need to convert the strings to integer ( cint(Array(n)) ) before we start our math (where n=your array element).

Reversing the computation wont be too hard. For example, converting hours to milliseconds:
accumulator = accumulator + (cint(array(0))*3.6e+6)

just work thru the array(n) using the correct conversion and add that to the total accumulator.

Once you have the accumulated total, store that value in [elapsedtime] for the record, move next record, rinse-repeat until end of record-set is found.
Dec 25 '15 #23
NeoPa
32,556 Expert Mod 16PB
hvsummer:
@Neopa as you said lets system handle that, I was thinking why he has to save everything in that time format ?
hh:mm:ss.ms ?
I believe he's said that he's holding the data in string format. I believe it makes most sense to store the data as a Date/Time. It just makes everything so much easier. Certainly you can convert it to and from various integer formats, and hold them either separately or together, but I just don't see the benefit when you have a storage format that suits the situation perfectly.

This all just seems to me to be overcomplicating matters. It should still work mind, and whatever works for people is fine. If they find they can understand a complicated situation more easily when doing it a particular way then that shouldn't be discounted. After all, my preferences are mine. I would no more expect others to take those on than I'd be prepared to take others' preferences on myself.
Dec 26 '15 #24

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Job Lot | last post by:
how can i create a stop watch using vb.net i am performing a data extraction job using windows forms and want to display time elapsed on the form. how can i do it? Thanks
0
by: theprogrammer01 | last post by:
i needed to use the timer function as a stopwatch to put a start time and a end time in two different cells on a worksheet
8
by: shyamg | last post by:
here iam using in my page time text field when page is the time is runing ok its fine but when page is loded ofter the time will be stoped how....its posible ...plz tell me i want only the display...
6
by: aliusmankhan | last post by:
Hi all I have developed an online testing system, Its time based test, I used AJAX TIMER to show the user that how much time left for the test, But when AJAX timer refresh in every sec, it makes...
4
by: Rajneesh Chellapilla | last post by:
I wrote this program. Its kinda of strange when I make a reset function reset(){c=0} its doest reset the setTimeout. However if I directly pass c=0 to the onclick button it does reset the timer. What...
9
by: Ross | last post by:
I'm a newbie at this, and have searched a lot but can't find something that seems appropriate for measuring a recurring elapsed time. Creating an object with: var mydate = new Date(); seems...
11
by: uzairmemon | last post by:
Any one Have coding of Reverse stop watch?
26
RockKandee
by: RockKandee | last post by:
Hi! I am using Access 2013 with Windows 8 I am working with this calendar http://http://bytes.com/topic/access/answers/761255-ms-access-calendar I would like to know if there is a quick...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...

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.