FUNCOES DE HORA

USUARIO.EXCLUIDOS 06/07/2004 17:13:30
#32500
Gostaria dos seguintes códigos:

Adicionar x segundos a um valor hora, por exemplo, 12:45:50;
Adicionar x minutos
Adicionar x horas

Subtrair x minutos
Subtrair x horas
Subtrair x minutos
CAJU 07/07/2004 11:36:58
#32607
Resposta escolhida
talvez te ajude:

Public Function AddDateTime(sTime As String, ToDate As Date) As Date
Dim sStartFrom As String
Dim blnIsNegative As Boolean
Dim intTotLen As Integer
Dim sMinutes As Variant
Dim dtAddedDateHour As Date
Dim dtAddedDateMinutes As Date
dtAddedDateHour = DateAdd("H", sTime, Format(ToDate & " 00:00", "mm/dd/yyyy HH:MM"))


If InStr(sTime, "-") <> 0 Then
blnIsNegative = True
End If


If InStr(sTime, ".") <> 0 Then
sStartFrom = InStr(sTime, ".") '*** Get the start point of Decimal
intTotLen = Len(sTime) ' *** Get Total length of time
sMinutes = Right(sTime, intTotLen - sStartFrom) '*** Get only Decimal part(Minutes)


If Len(sMinutes) = 1 Then


If blnIsNegative Then
sMinutes = -(sMinutes * 10)
Else
sMinutes = sMinutes * 10
End If
Else


If blnIsNegative Then
sMinutes = -sMinutes
Else
sMinutes = sMinutes
End If
End If
End If
dtAddedDateMinutes = DateAdd("N", sMinutes, dtAddedDateHour)
AddDateTime = dtAddedDateMinutes
End Function


Private Sub Form_Load()
MsgBox AddDateTime("00.34", Date)
End Sub
Tópico encerrado , respostas não são mais permitidas