[Lazarus] DateDif function needed

John Landmesser JohnML at online.de
Wed Nov 13 11:19:38 CET 2013


On 13.11.2013 02:33, waldo kitty wrote:
>
> actually, i have in some cases... let's ask this question and see what 
> your charts and routines return as the result... assuming your format 
> is DD.MM.YYYY...
>
> Date1 := 01.01.2000
> Date2 := 01.01.2000
>
> should be 0 (zero), right?
>
> then
>
> Date1 := 01.01.2000
> Date2 := 02.01.2000
>
> should be 1 (one), right?
>
> in this case, what i (and bart, too) wrote, we're not counting the 
> starting day but we are counting the ending day... this rule stays in 
> effect throughout the entire process... my head still aches from 
> rummaging about doing this... it was good exercise and one i remember 
> being given on a test many years back to determine one's coding 
> level... at that time, the code was being done in dBase II/III/IV ;)
>
> i will have to dig deeper and see what is crossing things up for count 
> from 29.02.2000 to 28.02.2001... i see bart has posted a fix which i 
> have not yet had a chance to compare with my code or run thru the 
> tests i included in my posting...
>
> the real question is this:
>
>   what do we count? the starting day, the ending day, both days or 
> neither day?
>
> then we have another question:
>
>   is dayM in monthY a one month difference to dayM in monthX and
>   monthZ? monthX, monthY, monthZ are any three consecutive months
>   in linear order within one year or crossing two years
>
> once the rules are chosen, then we have something to work with...
>

I'm just a hobbyist, never went to university to study computer science.

We don't need to invent the wheel again, because others have solutions 
for that!

Perhaps its solved in " The Art of/Computer Programming/" from Donald E. 
Knuth?

I don't have such books and i don't know if i'd have the chance to 
understand such a book?!!

Yesterday i was running windows on this PC and tried MS Visual Studio 
2008 Help.
That showed me ( -> DateDiff ) a Tutorial from a MS-India guy that 
delivered code to calculate DateDiff.

I'm now running Linux but perhaps i reboot later to look again?

Bart delivered code that calculates 29.02.2000 to 28.02.2001 = 1 Year.
And that looks reasonable to me!

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.
>
> Bart

Soon we'll have working DateDiff function and my question will be 
answered in the end!
Thanks guys!!


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20131113/b6596112/attachment-0003.html>


More information about the Lazarus mailing list