|
|
|
|
|
Dicas
|
|
Visual Basic (ActiveX/Controles/DLL)
|
|
|
Título da Dica: Cálculo de horas e minutos de um intervalo
|
|
|
|
Postada em 5/2/2007 por ¨Hennyere¨
Public Function CalculaIntervalo(h1 As String, h2 As String) As String If CDate(h1) > CDate(h2) Then h2 = TransformaTempo(h2) CalculaIntervalo = CDbl(Mid(h1, 1, 2) & Mid(h1, 4, 2)) - CDbl(Mid(h2, 1, 2) & Mid(h2, 4, 2)) If Right(CalculaIntervalo, 2) > 59 Then CalculaIntervalo = CalculaIntervalo - 60 Select Case Len(CalculaIntervalo) Case 2 CalculaIntervalo = "00:" & CalculaIntervalo Case 3 CalculaIntervalo = "0" & Mid(CalculaIntervalo, 1, 1) & ":" & Mid(CalculaIntervalo, 2, 2) Case 4 CalculaIntervalo = Mid(CalculaIntervalo, 1, 2) & ":" & Mid(CalculaIntervalo, 3, 2) Case 5 CalculaIntervalo = Mid(CalculaIntervalo, 1, 3) & ":" & Mid(CalculaIntervalo, 4, 2) Case 6 CalculaIntervalo = Mid(CalculaIntervalo, 1, 4) & ":" & Mid(CalculaIntervalo, 5, 2) Case Else CalculaIntervalo = "00:00" End Select If Left(CalculaIntervalo, 1) = "-" Then CalculaIntervalo = Mid(CalculaIntervalo, 2, 6) End Function Private Function TransformaTempo(cTempo As String) As String Dim i As Integer For i = 0 To 23 If Int(Mid(cTempo, 1, 2)) = i Then _ TransformaTempo = i + 24 & Mid(cTempo, 3, 3) Next End Function
'Josefh Hennyere
|
|
|
|
|