<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">On 08.11.2013 21:35, John Landmesser
wrote:<br>
</div>
<blockquote cite="mid:527D4B21.9000801@online.de" type="cite">Hi
List,
<br>
<br>
i'm searching a pascal datetime function that simulates an Excel
function: "DateDif"
<br>
<br>
Excel for example knows the function DateDif that returns the
number of Years, month and days between Date1 and date2.
<br>
<br>
Date1 := 21.12.2012
<br>
Date2 := 01.01.2013
<br>
<br>
Result would be: 0 years, 0 moths, 11 days
<br>
<br>
I tried to do it on my own, but without success.
<br>
<br>
But i think there is a function out there but i don't know its
name :-((
<br>
<br>
Thanks for your tipps
<br>
<br>
John
<br>
<br>
--
<br>
_______________________________________________
<br>
Lazarus mailing list
<br>
<a class="moz-txt-link-abbreviated" href="mailto:Lazarus@lists.lazarus.freepascal.org">Lazarus@lists.lazarus.freepascal.org</a>
<br>
<a class="moz-txt-link-freetext" href="http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus">http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus</a>
<br>
</blockquote>
<br>
<br>
Found a solution in Jedi: /jvcl/run/JvJCLUtils.pas<br>
<br>
procedure DateDiff(Date1, Date2: TDateTime; var Days, Months, Years:
Word<br>
);<br>
var<br>
DtSwap: TDateTime;<br>
Day1, Day2, Month1, Month2, Year1, Year2: Word;<br>
begin<br>
if Date1 > Date2 then<br>
begin<br>
DtSwap := Date1;<br>
Date1 := Date2;<br>
Date2 := DtSwap;<br>
end;<br>
DecodeDate(Date1, Year1, Month1, Day1);<br>
DecodeDate(Date2, Year2, Month2, Day2);<br>
Years := Year2 - Year1;<br>
Months := 0;<br>
Days := 0;<br>
if Month2 < Month1 then<br>
begin<br>
Inc(Months, 12);<br>
Dec(Years);<br>
end;<br>
Inc(Months, Month2 - Month1);<br>
if Day2 < Day1 then<br>
begin<br>
// von mir auskommentiert Inc(Days, DaysPerMonth(Year1,
Month1));<br>
Inc(Days, DaysInAMonth(Year1, Month1));<br>
if Months = 0 then<br>
begin<br>
Dec(Years);<br>
Months := 11;<br>
end<br>
else<br>
Dec(Months);<br>
end;<br>
Inc(Days, Day2 - Day1);<br>
end;<br>
<br>
**************************************<br>
<br>
Seems to calculate ok. <br>
Now i'll try to understand what it is doing :-))<br>
<br>
<br>
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<style type="text/css">
p, li { white-space: pre-wrap; }
</style>
</body>
</html>