On 08.11.2013 21:35, John Landmesser wrote:
Hi List,

i'm searching a pascal datetime function that simulates an Excel function: "DateDif"

Excel for example knows the function DateDif that returns the number of Years, month and days between Date1 and date2.

Date1 := 21.12.2012
Date2 := 01.01.2013

Result would be: 0 years, 0 moths, 11 days

I tried to do it on my own, but without success.

But i think there is a function out there but i don't know its name :-((

Thanks for your tipps

John

--
_______________________________________________
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Hi list,

This discussion seems to be finished ( 92 posts ) and i want to make a proposal as solution:

Use the function DateDiff from Jedi ( RxLib ) ( JvJCLUtils.pas ).

It's not perfect, but it works for me:

**********************************************

procedure DateDiff(Date1, Date2: TDateTime; var Days, Months, Years: word);
var
  DtSwap: TDateTime;
  Day1, Day2, Month1, Month2, Year1, Year2: word;
begin
  if Date1 > Date2 then
  begin
    DtSwap := Date1;
    Date1 := Date2;
    Date2 := DtSwap;
  end;
  DecodeDate(Date1, Year1, Month1, Day1);
  DecodeDate(Date2, Year2, Month2, Day2);
  Years := Year2 - Year1;
  Months := 0;
  Days := 0;
  if Month2 < Month1 then
  begin
    Inc(Months, 12);
    Dec(Years);
  end;
  Inc(Months, Month2 - Month1);
  if Day2 < Day1 then
  begin
    // von mir auskommentiert Inc(Days, DaysPerMonth(Year1, Month1));
    Inc(Days, DaysInAMonth(Year1, Month1));
    if Months = 0 then
    begin
      Dec(Years);
      Months := 11;
    end
    else
      Dec(Months);
  end;
  Inc(Days, Day2 - Day1);
end;

**********************************************

Hope that statement is usefull for somebody reading this thread.

I couldn't find any bug report on "Project JEDI - Issue Tracker".

Thanks for this discussion!

John
--
_______________________________________________
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to