[Lazarus] DateDif function needed

waldo kitty wkitty42 at windstream.net
Wed Nov 13 18:31:00 CET 2013

On 11/13/2013 9:37 AM, John Landmesser wrote:
> On 13.11.2013 14:02, waldo kitty wrote:
>>> We don't need to invent the wheel again, because others have solutions for that!
>> then why does this thread exist? O:)
> I'll try to find what the usual way is to handle these problems: c++ Libraries
> for example?!

i was being facetious thus the smiley ;)

>> i don't know as i do not have that book... but since you have the three
>> routines available, can you please post what they return for the two cases
>> above??
> I don't have my test app anymore, changed it a lot last days to follow the
> discussion, but perhaps you have a look at my post from 12.11.2013,  21:56

i know that feeling... i've taken to trying to save each in its own project so 
that i still have them to go back to to look over ;)

>> [...]
>>> Bart delivered code that calculates 29.02.2000 to 28.02.2001 = 1 Year.
>>> And that looks reasonable to me!
>> but it is not, not really... 29.02 only comes around once every four years...
>> 29.02.leapyear to 28.02.leapyear+1 is one day short of a year... if you were
>> born on 29.02.1960, have you celebrated your birthday 13 or 53 times? :)
> That depends on the country , you're living, see
> http://en.wikipedia.org/wiki/February_29#Births

yeah, i've heard that, too... however, my experience shows that it is personal 
preference in many cases... i have several friends born on 29 Feb and some of 
them count every full year as their age but only celebrate on leapyears while 
others only count the leapyears... then there's the one oddball who celebrates 
every year but only counts the leapyears :lol:

>>> Bart wrote:
>>>> I would actually say that in this particular case the diff is 1 Year...
>>>> (11 M + (28 days in feb in a non-leapyear = 1M) = 12M = 1 Y.
>>> Soon we'll have working DateDiff function and my question will be answered in
>>> the end!
>>> Thanks guys!!
>> i can, however, agree with the reasoning bart has given above... do you agree
>> with it? is that what you want to see?
> I'm not the one to decide, but i need a function which provides widely accepted
> results!

as lex edmonds spoke of, there are two types of calculations... inclusive and 
exclusive where the ending day is counted or not... then there is also whether 
we are looking to use (strict) intervals or calendar intervals... if i have been 
keeping up, you are looking for calendar intervals (based on your post where 
01.01.2000 to 01.08.2001 should be 1 year, 7 months)...

as far as "not one to decide"... on the contrary... you are the one to decide if 
a routine fits your purposes... as far as accepting a routine to be added to one 
of the libraries distributed with FPC and/or Lazarus, yeah, that's up to someone 
on those teams...

> I'll google again.
>> which of the following is what you want to see??
>> 2000-02-29 to 2001-02-28 is    0 yrs   11 mos   27 days (original)
>> 2000-02-29 to 2001-02-28 is    0 yrs   11 mos   28 days  (bart's fix)
>> 2000-02-29 to 2001-02-28 is    1 yrs    0 mos    0 days  (actually desired?)

so which one of these are you actually 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