como calcular dias entre uma data presente e passada
como faço esse cálculo?
ex:
10/03/2005 - 01/03/2005 = 9
e se caso for ao contrário, tem como resultar em um valor negativo?
ex:
01/03/2005 - 10/03/2005 = -9
tks
ex:
10/03/2005 - 01/03/2005 = 9
e se caso for ao contrário, tem como resultar em um valor negativo?
ex:
01/03/2005 - 10/03/2005 = -9
tks
Henrique Rodrigues
Curtidas 0
Respostas
Joaoshi
10/03/2005
Colega,
StrToDate(10/03/2005) - StrToDate(01/03/2005) = 9
StrToDate(01/03/2005) - StrtoDate(10/03/2005) = -9
espero ter ajudado.
StrToDate(10/03/2005) - StrToDate(01/03/2005) = 9
StrToDate(01/03/2005) - StrtoDate(10/03/2005) = -9
espero ter ajudado.
GOSTEI 0
Diogoalles
10/03/2005
function DifDateUtil(dataini,datafin:string):integer; var a,b,c:tdatetime; ct,s:integer; begin if StrToDate(DataFin) < StrtoDate(DataIni) then begin Result := 0; exit; end; ct := 0; s := 1; a := strtodate(dataFin); b := strtodate(dataIni); if a > b then begin c := a; a := b; b := c; s := 1; end; a := a + 1; while (dayofweek(a)<>2) and (a <= b) do begin if dayofweek(a) in [2..6] then begin inc(ct); end; a := a + 1; end; ct := ct + round((5*int((b-a)/7))); a := a + (7*int((b-a)/7)); while a <= b do begin if dayofweek(a) in [2..6] then begin inc(ct); end; a := a + 1; end; if ct < 0 then begin ct := 0; end; result := s*ct; end;
abraço
Diogo
GOSTEI 0
Rômulo Barros
10/03/2005
[color=red:611114907a][b:611114907a]Respondendo:[/b:611114907a][/color:611114907a]
:arrow: [color=red:611114907a][u:611114907a][b:611114907a]Obs:[/b:611114907a][/u:611114907a][/color:611114907a] O método DaysBetween retorna a diferença de dias entre duas datas.[/b]
Uses DateUtils; ... ... procedure TForm1.Teste; Var Data2, Data1 : TDateTime ; Resultado : Integer ; begin Data1 := StrToDate(´01/03/2005´); Data2 := StrToDate(´10/03/2005´); If(Data1 >= Data2)Then Resultado := DaysBetween(Data2,Data1) Else Resultado := - DaysBetween(Data1,Data2); ShowMessage(IntToStr(Resultado)); end;
:arrow: [color=red:611114907a][u:611114907a][b:611114907a]Obs:[/b:611114907a][/u:611114907a][/color:611114907a] O método DaysBetween retorna a diferença de dias entre duas datas.[/b]
GOSTEI 0
Henrique Rodrigues
10/03/2005
Undeclared Identifier
obrigado, serviu como uma luva!
valeu a todos que ajudaram tb
obrigado, serviu como uma luva!
valeu a todos que ajudaram tb
GOSTEI 0