Fórum Calcular Tempo de trabalho ????? #270016
24/02/2005
0
ex 1 ano e 8 meses* ou algo q fique parecido.
Grato
Guilherme
gborges_13@yahoo.com.br
Guilherme
Curtir tópico
+ 0Posts
24/02/2005
Marcio.theis
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, Mask;
type
TForm1 = class(TForm)
dtNasc: TMaskEdit;
SpeedButton1: TSpeedButton;
edtTempo: TEdit;
function Bissexto(AYear: Integer): Boolean;
function DiasDoMes(AYear, AMonth: Integer): Integer;
function Tempo(DataNasc : TDate) : String;
function Dias(Data : TDate) : String;
procedure SpeedButton1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function TForm1.Bissexto(AYear: Integer): Boolean;
begin
Result:=(AYear mod 4 = 0) and ((AYear mod 100 <> 0) or (AYear mod 400 = 0));
end;
function TForm1.DiasDoMes(AYear, AMonth: Integer): Integer;
const
DaysInMonth: array[1..12] of Integer = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
begin
Result:=DaysInMonth[AMonth];
if (AMonth = 2) and Bissexto(AYear) then
Inc(Result);
end;
function TForm1.Tempo(DataNasc : TDate) : String;
var
Ano1, Mes1, Dia1 : Word;
Ano2, Mes2, Dia2 : Word;
Ano, Mes, Dia : Word;
Idade : String;
AuxDia1, AuxDia2 : Integer;
begin
Idade:=´´;
DecodeDate(DataNasc, Ano1, Mes1, Dia1);
DecodeDate(Date, Ano2, Mes2, Dia2);
AuxDia1:=Dia1;
AuxDia2:=Dia2;
if (Dia1 > Dia2) and ((Mes2 - Mes1) = 1) then
begin
Dia2:=Dia2 + DiasDoMes(Ano1, Mes1);
Mes1:=Mes2;
end
else
if (Dia1 > Dia2) and (Mes1 <> Mes2) then
begin
Dia2:=Dia2 + DiasDoMes(Ano1, Mes1);
end
else
if (Mes1 = Mes2) and (Dia1 > Dia2) and (Ano1 <> Ano2) then
begin
Dia2:=Dia2 + DiasDoMes(Ano1, Mes1);
Mes2:=Mes2 + 11;
Ano1:=Ano1 + 1;
end;
if (Mes1 > Mes2) and (AuxDia1 <= AuxDia2) then
begin
Ano1:=Ano1 + 1;
Mes2:=Mes2 + 12;
end
else
if (Mes1 > Mes2) and (AuxDia1 > AuxDia2) then
begin
Ano1:=Ano1 + 1;
Mes2:=Mes2 + 11;
end;
Ano:=Ano2 - Ano1;
Mes:=Mes2 - Mes1;
Dia:=Dia2 - Dia1;
if Ano > 1 then
Idade:=IntToStr(Ano) + ´ Anos´
else
if Ano = 1 then
Idade:=IntToStr(Ano) + ´ Ano´;
if Mes > 1 then
Idade:=Idade + ´, ´ + IntToStr(Mes) + ´ Meses ´
else
if Mes <> 0 then
Idade:=Idade + ´, ´ + IntToStr(Mes) + ´ Mês ´;
If Ano = 0 then
Delete(Idade, 1, 1);
if Dia > 1 then
Idade:=Idade + ´ e ´ + IntToStr(Dia) + ´ Dias´
else
if Dia <> 0 then
Idade:=Idade + ´ e ´ + IntToStr(Dia) + ´ Dia´;
if (Mes = 0) and (Ano = 0) then
Delete(Idade, 1, 3);
if (Ano1 = Ano2) and (Mes1 = Mes2) and (Dia1 > Dia2) then
Idade:=´0´;
Result:=Idade;
end;
function TForm1.Dias(Data : TDate) : String;
begin
Result:=FloatToStr(Date - Data);
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
edtTempo.Text:=Tempo(StrToDate(dtNasc.Text));
end;
end.
No lugar de StrToDate(dtNasc.Text) passa o seu campo com a data desejada.
Gostei + 0
24/02/2005
Guilherme
Desculpa sou mto novato .......
Gostei + 0
24/02/2005
Marcio.theis
Gostei + 0
24/02/2005
Guilherme
Gostei + 0
24/02/2005
Vprates
Var vAno, vMes, vDia: Integer;
begin
vAno:=yearsBetween(Date, TuaData);
vMes:=MonthsBetween(Date, TuaData);
vDia:=DaysBetween(Date, TuaData);
Label.caption:=IntToStr(vAno)+´ anos, ´+IntToStr(vMes)+´ Meses e ´+IntToStr(vDia);
Espero que isso te ajude...
Obs Tem q incluir a Unit DateUtils nas Uses
Gostei + 0
25/02/2005
Guilherme
o ultimo exemplo do nosso amigo vprates ja funcionou melhor mas ainda nao é o q eu espero , o exemplo fornecido mostra por exemplo ce eu colocar a data de 1 ano atraz fica exatamente assim : 1 Ano 12 Meses 365 dias eu estou presisando que mostre a quantia de anos meses e dias exemplo : o funcionario foi cadastrado dia 24/01/05 e hoje é 25/02/04 ai gostaria de q retornace assim : 0 anos 0 meses 1 dia
um outro exemplo :o funcionario foi cadastrado dia 24/03/05 e hoje é 25/04/04 ai retorna assim 0 anos 1 mes 1 dia .
espero ter esplicado melhor ....
Gostei + 0
25/02/2005
Gabriela
procedure CalculaDiferenca(inicio, fim: tdate; var year, month, day: integer); var y1,y2,m1,m2,d1,d2: integer; begin y1 := YearOf(fim); y2 := YearOf(inicio); m1 := MonthOf(fim); m2 := MonthOf(inicio) ; d1 := DayOf(fim); d2 := DayOf(inicio); year := y1 - y2; if (m1 >= m2) then month := m1 - m2 else month := m1 - m2 + 12; if (d1 >= d2) then day := d1 - d2 else day := d1 - d2 + 30; end;
Só o calculo da diferença de dias que não esta preciso, pq eu considero que tdos os meses tem 30 dias, mas aí é so fazer um pqno tratamento. O principal está ai. Não testei, mas deve funcionar.
Gostei + 0
25/02/2005
Marcio.theis
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)