time in VBA

G2K

Active Member
Joined
May 29, 2009
Messages
355
Hi All,

i need to built a tracker where user input two time stamps Like - 10:25:35 and 12:22:33 in excle through User form and the output should be the diffrence between input time. user input time in three text boxes - for Hour,Minute and secs respectively

Dim loginT, logout, logoutT, totalT As Date

loginT = txtLTHH.Text & ":" & txtLTMM.Text & ":" & txtLTSS.Text
logout = txtLOHH.Text & ":" & txtLOMM.Text & ":" & txtLOSS.Text

but when i pass this parameter in my UDF it generates type mismatch Error.
Logout = MinusTime(LogoutT,LoginT) 'Type Mismatch error.

UDF -

Public Function MinusTime(t1 As Date, t2 As Date) As String
Dim T1sec As Double
Dim T2sec As Double
Dim totalsecs As Double
Dim h As Double
Dim m As Double
Dim s As Double
Dim final As String
T1sec = (Hour(t1) * 60 * 60) + (Minute(t1) * 60) + Second(t1)
T2sec = (Hour(t2) * 60 * 60) + (Minute(t2) * 60) + Second(t2)
If T1sec < T2sec Then
final = "00:00:00"
Else
totalsecs = T1sec - T2sec
h = (totalsecs Mod 86400) \ 3600
m = ((totalsecs Mod 86400) Mod 3600) \ 60
s = ((totalsecs Mod 86400) Mod 3600) Mod 60
final = VBA.Format(h, "00") & ":" & VBA.Format(m, "00") & ":" & VBA.Format(s, "00")
End If
MinusTime = final
End Function


Please help.........
 
Last edited:

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Perhaps

Code:
Dim loginT As Date, logout As Date, logoutT As Date, totalT As Date
loginT = TimeValue(LTHH.Text & ":" & LTMM.Text & ":" & LTSS.Text)

and so on.
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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