Calculating time difference between timestamps

vbaBaby

New Member
Joined
Mar 27, 2015
Messages
12
Hi

I'm trying to calculate the difference in times on a userform. I have a start time, pause, continue and end times which are entered using time stamps with the NOW() funtion. I've calculated but it returns an actual "hour" rather than the time difference. I'm completely new at this and now done VBA coding before, please bear with me. Here is the code:

Private Sub StartButton_Click()
'Inserts the start time and date
'Start time function
Dim BeginTime As Double
BeginTime = Now()
StatsCapture.BeginTimeBox.Value = BeginTime
End Sub


Private Sub PauseButton_Click()
'Inserts the pause time
'Pause time function


'Checks if timer has been started
If StatsCapture.BeginTimeBox.Value = "" Then
MsgBox "Timer has not been started!"
Exit Sub
End If

Dim PausedTime As Double
PausedTime = Now()

StatsCapture.PausedTimeBox.Value = PausedTime


End Sub



Private Sub ContinueButton_Click()
'Inserts the pause time
'Pause time function

'Checks if timer has been started
If StatsCapture.BeginTimeBox.Value = "" Then
MsgBox "Timer has not been started!"
Exit Sub
End If

'Checks if timer has been paused
If StatsCapture.PausedTimeBox.Value = "" Then
MsgBox "Timer is not paused!"
Exit Sub
End If

Dim ContinuedTime As Double
ContinuedTime = Now()

StatsCapture.ContinuedTimeBox.Value = ContinuedTime

End Sub


'Calculates the duration of the query
Dim Duration As Double

If StatsCapture.BeginTimeBox.Value = "" Then
Duration = ManualTime.Value
Else:
Duration = EndTime + PausedTime - BeginTime - ContinuedTime
End If

When I transfer the data to the worksheet, the time returns like this instead "27-03-2015 16:19:38" instead of proper calc of minutes taken
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Have you tried formatting it before sending it back?

i.e.:
Code:
TimeTaken = Format(Duration, "mm:ss.0")
 
Upvote 0

Forum statistics

Threads
1,215,332
Messages
6,124,314
Members
449,153
Latest member
JazzSingerNL

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top