Question : DELPHI - DATEDIFF

I have a variable with two dates DATAINIZIO - DATAFINE
There is a function included in Delphi to calculate the difference between the two dates, I need to get the result in days, months, years, hours and seconds?

I would like an example. thanks

Answer : DELPHI - DATEDIFF

Date 0 in Delphi is actually 1899-12-30, so you get a strange result.
Use this function instead, which will return the 7 components of a date diff.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
procedure DiffDates(dFrom, dTo: TDateTime; var y,m,d,h,n,s,ms: Word);
begin
  DecodeTime(dFrom-dTo, h,n,s,ms);
  y := 0; m := 0; d := 0;
  while IncMonth(dFrom,12*y) < dTo do
    Inc(y);
  if IncMonth(dFrom,12*y) > dTo then
    Dec(y);
  dFrom := IncMonth(dFrom,12*y);
  while IncMonth(dFrom,m) < dTo do
    Inc(m);
  if IncMonth(dFrom,m) > dTo then
    Dec(m);
  dFrom := IncMonth(dFrom, m);
  while dFrom + d < dTo do
    Inc(d);
  if dFrom + d > dTo then
    Dec(d);
end;
Random Solutions  
 
programming4us programming4us