Fórum Calculo com Horas - Urgente #177370
25/08/2003
0
Utilizo banco de dados Interbase, e tenho um tabela q o tempo gasto em horas e minutos e tenho q somar todas estas horas e fazer a media.
Exemplo:
registro 1 tempo 01:15
registro 2 tempo 00:55
registro 3 tempo 02:12
registro 4 tempo 03:35
preciso do tempo total ?
e a media = tempo total / quantidade de registros
tudo feito no select sum(tempo) as ttempo count(tempo) as qtempo from tabela.
sds
Anderson
Exemplo:
registro 1 tempo 01:15
registro 2 tempo 00:55
registro 3 tempo 02:12
registro 4 tempo 03:35
preciso do tempo total ?
e a media = tempo total / quantidade de registros
tudo feito no select sum(tempo) as ttempo count(tempo) as qtempo from tabela.
sds
Anderson
Agaraujo
Curtir tópico
+ 0
Responder
Posts
25/08/2003
Marconi
No exemplo que eu tenho, a tabela guarda todas as vezes que o funcionário trabalhou em uma determinada Ordem de Serviço e faz a soma. Neste caso a tabela OS e a master source do da tabela Trabalhos.
A função Strzero ajusta a string para o tamanho desejado com zeros a esquerda. Eu já passei esta função em perguntas anteriores.
procedure TfControle.TotalizaHoras;
var Hour, Min, Sec, MSec :word; totH,totM: Integer;
begin
totH:=0; totM:=0;
fCTrabalhos.first;
while not fConsulta.Trabalhos.eof do begin
if (Trabalhos[´fim´]<>null) and (fConsulta.Trabalhos[´inicio´]<>null) then begin
DecodeTime(Trabalhos[´fim´],Hour,Min,Sec,Msec);
totH:=totH+Hour;
totM:=totM+Min;
DecodeTime(Trabalhos[´inicio´],Hour,Min,Sec,Msec);
totH:=totH-Hour;
totM:=totM-Min;
end;
Trabalhos.next;
end;
while totM>=60 do begin
inc(totH);
totM:=totM-60;
end;
while totM<0 do begin
dec(totH);
totM:=totM+60;
end;
os.edit;
os[´TotalHoras´]:=IntToStr(totH)+´:´+Strzero(totM,2);
os.post;
end;
Cordialmente
Marconi
A função Strzero ajusta a string para o tamanho desejado com zeros a esquerda. Eu já passei esta função em perguntas anteriores.
procedure TfControle.TotalizaHoras;
var Hour, Min, Sec, MSec :word; totH,totM: Integer;
begin
totH:=0; totM:=0;
fCTrabalhos.first;
while not fConsulta.Trabalhos.eof do begin
if (Trabalhos[´fim´]<>null) and (fConsulta.Trabalhos[´inicio´]<>null) then begin
DecodeTime(Trabalhos[´fim´],Hour,Min,Sec,Msec);
totH:=totH+Hour;
totM:=totM+Min;
DecodeTime(Trabalhos[´inicio´],Hour,Min,Sec,Msec);
totH:=totH-Hour;
totM:=totM-Min;
end;
Trabalhos.next;
end;
while totM>=60 do begin
inc(totH);
totM:=totM-60;
end;
while totM<0 do begin
dec(totH);
totM:=totM+60;
end;
os.edit;
os[´TotalHoras´]:=IntToStr(totH)+´:´+Strzero(totM,2);
os.post;
end;
Cordialmente
Marconi
Responder
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)