SOMAS DE HORAS

USUARIO.EXCLUIDOS 26/04/2007 22:17:25
#213944
Olá pessoal!
Minha dúvida é o seguinte:
No meu, sistema q estou desenvolvendo, no módulo funcionários eu tenho a opção para registras as horas a mais ou a menos trabalhadas.
Depois eu monto um relatório mostrando o total de horas pendentes, ou não.

Como q eu faço para somar as horas sendo q os segundos quando chega nos 60 tem q voltar para o um?
CLEVERTON 27/04/2007 08:46:25
#213971
'Acho que é mais ou menos assim (não manjo de asp)
<%Objeto.Value = DateAdd("h",5,"12:00")%>
USUARIO.EXCLUIDOS 27/04/2007 08:59:29
#213976
não entendi muito bem o q vc quis dizer.

Eu faço isso quando eu recupero o dado do formulário e depois é só somar q da certo?
RODRIGOGBGOMES 27/04/2007 09:07:49
#213977
da uma olhada Aqui
BRUNO.DUARTE 27/04/2007 09:17:24
#213979
Veja as Funções que criei em VB. Se precisar passe para ASP

Function SomaHoras(ByVal dtaHora1 As String, ByVal dtaHora2 As String) As String
Dim H1 As Double, M1 As Double, S1 As Double
Dim H2 As Double, M2 As Double, S2 As Double
Dim h As Double, m As Double, s As Double
Dim Soma As Double

If dtaHora1 = "" Then dtaHora1 = "00:00:00"
If dtaHora2 = "" Then dtaHora2 = "00:00:00"

Soma = 0

If Len(dtaHora1) >= 9 Then
H1 = StrToNumber(Left(dtaHora1, 3))
M1 = StrToNumber(Mid(dtaHora1, 5, 2))
S1 = StrToNumber(Right(dtaHora1, 2))
Else
H1 = StrToNumber(Left(dtaHora1, 2))
M1 = StrToNumber(Mid(dtaHora1, 4, 2))
S1 = StrToNumber(Right(dtaHora1, 2))
End If


If Len(dtaHora2) >= 9 Then
H2 = StrToNumber(Left(dtaHora2, 3))
M2 = StrToNumber(Mid(dtaHora2, 5, 2))
S2 = StrToNumber(Right(dtaHora2, 2))
Else
H2 = StrToNumber(Left(dtaHora2, 2))
M2 = StrToNumber(Mid(dtaHora2, 4, 2))
S2 = StrToNumber(Right(dtaHora2, 2))
End If

'Caulcula Segundos
s = S1 + S2 + Soma
If s > 60 Then
Soma = s / 60
s = s Mod 60
ElseIf s = 60 Then
Soma = 1
s = 0
Else
Soma = 0
End If

Soma = Val(Soma)

'Caulcula Minutos
m = M1 + M2 + Soma
If m > 60 Then
Soma = m / 60
m = m Mod 60
ElseIf m = 60 Then
Soma = 1
m = 0
Else
Soma = 0
End If

Soma = Val(Soma)

'Caulcula Horas
h = H1 + H2 + Soma

If Len(Trim(Str(h))) <= 2 Then
SomaHoras = Format$(h, "00") & ":" & Format$(m, "00") & ":" & Format$(s, "00")
Else
SomaHoras = Format$(h, "000") & ":" & Format$(m, "00") & ":" & Format$(s, "00")
End If

End Function


Function DiminuiHoras(ByVal dtaHora1 As String, ByVal dtaHora2 As String) As String
Dim H1 As Integer, M1 As Integer, S1 As Integer
Dim H2 As Integer, M2 As Integer, S2 As Integer
Dim h As Integer, m As Integer, s As Integer
Dim D As Date
Dim intleft As Integer
Dim intleft2 As Integer

If dtaHora1 = "" Then dtaHora1 = "00:00:00"
If dtaHora2 = "" Then dtaHora2 = "00:00:00"

If dtaHora1 < dtaHora2 Then
D = dtaHora2
dtaHora2 = dtaHora1
dtaHora1 = D
End If

If Len(dtaHora1) = 8 Then
intleft = 2
Else
intleft = 3
End If

If Len(dtaHora2) = 8 Then
intleft2 = 2
Else
intleft2 = 3
End If

H1 = Left(dtaHora1, intleft)
M1 = Mid(dtaHora1, intleft + 2, 2)
S1 = Right(dtaHora1, 2)

H2 = Left(dtaHora2, intleft2)
M2 = Mid(dtaHora2, intleft2 + 2, 2)
S2 = Right(dtaHora2, 2)



'Caulcula Segundos
If S2 > S1 Then
M1 = M1 - 1
S1 = S1 + 60
End If
s = S1 - S2

'Caulcula Minutos
If M2 > M1 Then
H1 = H1 - 1
M1 = M1 + 60
End If
m = M1 - M2

'Caulcula Horas
h = H1 - H2

DiminuiHoras = Format$(h, "00") & ":" & Format$(m, "00") & ":" & Format$(s, "00")
End Function


USUARIO.EXCLUIDOS 27/04/2007 09:40:22
#213987
Legal mas tem um problema as funções de vcs tem dois argumentos eu vou ter vários ou um só pq isso vem de um registro de uma tabela.
Eu vou ter q fazer um Loop pra pegar todos os dias de um funcionário q trabalhou a mais ou a menos e depois fazer os calculos das horas, dependendo do tempo do funcionário na empresa vai ser muitos dias, consequentimente muitas horas...
RODRIGOGBGOMES 27/04/2007 10:15:40
#214004
TO TE MANDANDO A FUNÇÃO Q EU USO PRA APURAR UM CARTAO DE PONTO....
AI VC ADAPTA AI... EU USO UM LISTVIEW Q CARREGA INFORMAÇÕES DO BANCO TBM.
Function SomaSemana(NumeroSemana As Integer) As String
Dim Hora As Long, Hora1 As String, Hora2 As String
Dim min As Long
Dim DataX As Date, DataAnterior As Date
Dim sRet
Hora1 = ""
Hora2 = "00:00"
For X = 1 To lvw.ListItems.Count
If lvw.ListItems(X).SubItems(16) = NumeroSemana Then
DataX = lvw.ListItems(X).Text
If Hora1 = "" Then
Hora1 = Format(lvw.ListItems(X).SubItems(7), "hh:mm")
If X + 1 <= lvw.ListItems.Count Then
If lvw.ListItems(X + 1).SubItems(16) = NumeroSemana Then
Hora2 = Format(lvw.ListItems(X + 1).SubItems(7), "hh:mm")
DataAnterior = lvw.ListItems(X + 1).Text
Hora = CLng(Left(Hora1, InStr(1, Hora1, ":") - 1))
Hora = Hora + CLng(Left(Hora2, InStr(1, Hora2, ":") - 1))
min = CLng(Right(Hora1, 2))
min = min + CLng(Right(Hora2, 2))
If min >= 60 Then
Hora = Hora + 1
min = min - 60
End If
sRet = Format(Hora & ":" & Format(min, "00"), "short time")
SomaSemana = sRet
Hora1 = sRet
End If
End If
Else
If Not DataAnterior = DataX Then
Hora2 = Format(lvw.ListItems(X).SubItems(7), "hh:mm")
Hora = CLng(Left(Hora1, InStr(1, Hora1, ":") - 1))
Hora = Hora + CLng(Left(Hora2, InStr(1, Hora2, ":") - 1))
min = CLng(Right(Hora1, 2))
min = min + CLng(Right(Hora2, 2))
If min >= 60 Then
Hora = Hora + 1
min = min - 60
End If
sRet = Format(Hora & ":" & Format(min, "00"), "short time")
SomaSemana = sRet
Hora1 = sRet
End If
End If
End If
EnviaRecebeTotalSemana NumSemana, SomaSemana
RecebeResultados
Next X
End Function


USUARIO.EXCLUIDOS 07/05/2007 10:12:27
#215277
O Rodrigo ta dando um erro de tipo incompativel no "CLng" quando eu faço o calculo, vc sabe o q pode ser?
Tópico encerrado , respostas não são mais permitidas