ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Time Difference between two events (https://www.excelbanter.com/excel-programming/309198-time-difference-between-two-events.html)

Joseph[_34_]

Time Difference between two events
 
Hi Guys and Gals,

I have a start button. This should start a timer. The stop button(whe
clicked) should calculate the time difference between the start an
stop events. How would I do this? I am basically monitoring a user'
activities to see exactly how long it takes them to carry out a certai
task.

Cheers people
Josep

--
Message posted from http://www.ExcelForum.com


mangesh_yadav[_103_]

Time Difference between two events
 
when u click start, capture the current time and when you click sto
again capture the current time. find the difference between the two
Roughly speaking

startTime = now()
endTime = now()

totalTimeDays = endTime - startTime (this will give you time in days)

If you want in seconds, mutiply totalTimeDays with nos of seconds

totalTimeSecs = totalTimeDays * (24*60*60)

Manges

--
Message posted from http://www.ExcelForum.com


Joseph[_35_]

Time Difference between two events
 
Hi Mangesh,

This is more or less what I'm looking for, but I don't want the dat
part, I know you can use Format to to get what you want, but Im a bi
unsure as to the syntax? I need the difference to be displayed in HH:M
format?

Cheer

--
Message posted from http://www.ExcelForum.com


mangesh_yadav[_105_]

Time Difference between two events
 
so its all the more simple. you jsut have to find the diff i.e
totalTimeDays and then format the cell to display the result in HH:MM

Manges

--
Message posted from http://www.ExcelForum.com


Joseph[_36_]

Time Difference between two events
 
I see what you're saying, but this is going to be done in a form an
then saved to a database, so the formatting has to be done in code. Th
other problem i'm having is the the startTime and endTime variables ar
storing the same value from the Now() function. Here is the code:

Dim startTime, endTime
startTime = Now()
endTime = Now()
MsgBox (startTime)
MsgBox (endTime)
MsgBox (Format(startTime - endTime, "HH:MM:SS")

--
Message posted from http://www.ExcelForum.com


Joseph[_37_]

Time Difference between two events
 
Its ok Mangesh, I finally figured out that it was the position of the
variables in the code that was throwing it. Thanks for your help.


---
Message posted from http://www.ExcelForum.com/


mangesh_yadav[_107_]

Time Difference between two events
 
yes ofcourse. You need to place the start so that the line is executed
right after you click the start button. And similar is the end button

mangesh


---
Message posted from http://www.ExcelForum.com/



All times are GMT +1. The time now is 05:33 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com