[Lazarus] DateDif function needed

waldo kitty wkitty42 at windstream.net
Sun Nov 10 01:00:15 CET 2013


On 11/9/2013 1:41 PM, Michael Van Canneyt wrote:
>
>
> On Sat, 9 Nov 2013, waldo kitty wrote:
>
>>
>> digging deeper to work directly with YearsBetween and MonthsBetween shows that
>> they seem to be missing the usual "+0.5" generally used to ensure that
>> rounding is properly handled...
>
> You misunderstood these functions.
>
> There is no rounding necessary. The routines are correct.
>
> Only FULL years/months/day must be counted.

ahhh...

> See the documentation in e.g.
>
> http://www.freepascal.org/docs-html/rtl/dateutils/yearsbetween.html

yes, i've been digging in them all day since this thread came up ;)

> If you want partial years counted, you need the *Span functions.
>
> http://www.freepascal.org/docs-html/rtl/dateutils/yearspan.html

i'll have to look at those... i've been looking for something that can (without 
having to reinvent the wheel) show that the difference between

   2013 01 01 00:00:00.000 and
   2013 01 01 00:00:00:001 is
   0 Years, 0 Months, 0 Days, 0 Hours, 0 Minutes, 0 Seconds, 1 Msecond

whereas

   2013 01 01 00:00:00.000 and
   2013 01 01 00:00:00:100 is
   0 Years, 0 Months, 0 Days, 0 Hours, 0 Minutes, 0 Seconds, 100 Msecond

and

   2013 01 01 00:00:00.000 and
   2013 01 01 00:00:01:001 is
   0 Years, 0 Months, 0 Days, 0 Hours, 0 Minutes, 1 Seconds, 1 Msecond

and

   2013 01 01 00:00:00.000 and
   2014 02 02 01:01:01:001 is
   1 Years, 1 Months, 1 Days, 1 Hours, 1 Minutes, 1 Seconds, 1 Msecond

and also being able to include Weeks in there if we are eg: 1, 2 or 3 weeks into 
a month...

i will take a look at the SPAN functions and see if they will provide what i've 
been (silently) looking for ;)

-- 
NOTE: No off-list assistance is given without prior approval.
       Please keep mailing list traffic on the list unless
       private contact is specifically requested and granted.




More information about the Lazarus mailing list