Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Find the difference between two 'times' on the sam...
Author:
Sumedh
Submitted:
1/2/2001
Version:
VB6
Compatibility:
VB6
Category:
Date/Time
Views:
21287
Find the difference between two 'times' on the same day or on two different days... ie. time difference between: 11:30:00 on 03/01/01 22:00:20 on 04/01/01 Please use only 24 hr. format
Declarations:
'none
Code:
Public Function TimeDiff(LesserTime As String, LesserTimeDate As String, GreaterTime As String, GreaterTimeDate As String) As String Dim Thrs As Single, Tmins As Single, Tsecs As Single, ReturnTime As String Dim DTcheck As Single DTcheck = DateDiff("d", LesserTimeDate, GreaterTimeDate) If DTcheck > 0 Then For i = 0 To DTcheck Hour(GreaterTime) = Hour(GreaterTime) + 24 Next ElseIf DTcheck < 0 Then TimeDiff = "ERROR" Exit Function End If Thrs = Hour(GreaterTime) - Hour(LesserTime) If Thrs > 0 Then Tmins = Minute(GreaterTime) - Minute(LesserTime) If Tmins < 0 Then Tmins = Tmins + 60 Thrs = Thrs - 1 End If ElseIf Thrs = 0 And Minute(GreaterTime) > Minute(LesserTime) Then Tmins = Minute(GreaterTime) - Minute(LesserTime) Else TimeDiff = "ERROR" Exit Function End If Tsecs = Second(GreaterTime) - Second(LesserTime) If Tsecs < 0 Then Tsecs = Tsecs + 60 If Tmins > 0 Then Tmins = Tmins - 1 Else Tmins = 59 End If TimeDiff = TimeSerial(Thrs, Tmins, Tsecs) End Function
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement