This is my first post on this mailing list, so please bear with me. I used to do date calculations like this in the '80s when I was writing Real Estate software.
On Tue, 12 Nov 2013 20:33:00, waldo kitty wrote: > [...] > the real question is this: > > what do we count? the starting day, the ending day, both days or > neither day? > There are two types of days-between-dates calculations: Inclusive and Exclusive. Generally, the starting day should be considered the first day of the calculation. With an Inclusive calculation, the ending day is counted. With an Exclusive calculation, the ending day is not counted -- it is considered to be the first day of the following period. In Real Estate for example, date calculations are Inclusive. So a 1-week rent payment that starts on Monday 1 January 2007 ends on Sunday 7 January 2007. Therefore an Inclusive DateDiff calculation between 1/01/2007 and 7/01/2007 would return 7 days. Whereas an Exclusive calculation would return 6 days. Similarly, when calculating a person's age. A baby born on 1/01/2007 would be 7 days old on 7/01/2007. As I recall, Exclusive dates seem to be more applicable to financial calculations. For example, an Exclusive DateDiff calculation between 1/01/2007 and 1/04/2007 would return 3 months (not 3 months and 1 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... > This is a topic that has some tricky boundary conditions. Generally the rule is easy for days 1-27 in every month: The Inclusive DateDiff between day M in month 1 and Day M-1 in month 2 returns 1 month. e.g. between 28/01/2007 and 27/02/2007. However the rules get muddy with days 28-31. i.e. the "last few" days of every month. For example, an Inclusive DateDiff calculation between 29/01/2007 and 28/02/2007 should return 1 month. In my opinion, an Inclusive calculation between 30/01/2007 and 28/02/2007 should also return 1 month. And so should an Inclusive calculation between 31/01/2007 and 28/02/2007. In fact, we used to call these "calendar months" to differentiate them from "other" months that might always be defined as having perhaps 30 days. So as you see, there is no real hard answer to your question. It probably depend on what you are trying to achieve. Lex
-- _______________________________________________ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus