[Lazarus] DateDif function needed
waldo kitty
wkitty42 at windstream.net
Thu Nov 14 14:10:28 CET 2013
On 11/14/2013 4:41 AM, Reimar Grabowski wrote:
> On Thu, 14 Nov 2013 07:19:56 +0100
> Jürgen Hestermann <juergen.hestermann at gmx.de> wrote:
>
>> Am 2013-11-13 19:42, schrieb Reimar Grabowski:
>> > 1 julian year = 365.25 days of 86400 SI seconds each.
>> > Of course there are lots of other definitions for year but if FPC uses
>> > the julian one the value is exact and no approximation
>>
>>
>> So the difference between 2007-01-01 12:00 and 2008-01-01 12:00 ist *not*
>> one year?
> It is not one julian year. There is nothing like a year. As i said there
> are different definitions. If you talk about calendar year it's length
> changes and is therefor not a good measure of time and not used in science.
right but this whole thread was started because someone wanted a calendar based
datediff function which returns years, months and days... granted, they could
have used SI units of 86400 sec/day and 365.25 day's per year (30.4375
days/month) to calculate the difference between their ending date and the
current date in a continuous calculation but then looking at the calendar and
counting the ones they could see would be different...
start: 14 Nov 2013
end: 01 Aug 2018
days: 1721
1721 / 365.25 = 4.7118412047 years = 4 years
0.7118412047 * 365.25 = 260 days
260 / 30.4375 = 8.5420944559 months = 8 months
0.5420944559 = 30.4375 = 16.5 days
(trunc) 4 years, 8 months, 16 days
OR
(round) 4 years, 8 months, 17 days
FWIW: the routine we've been working on (with bug fix modifications) returns the
same output as the above (from openoffice calc)...
2013-11-14 to 2018-08-01 is 4 yrs 8 mos 17 days
yay! :lol:
>> It's only 365,00 days and therefore not a full year according to your
>> definition.
> Correct. And this is not my definition it is the correct definition of a
> julian year and it is based on SI units. Time is measured in SI seconds. If
> you cannot express 'your year' as seconds it is not a unit of time.
by who's definition of "time"? ;) O:)
>> But this it totaly wrong.
> Care to elaborate? Or is it just your gut feeling?
>
>> Same day same time of one year and the next should always be a one year
>> difference.
> According to what definition of year? Calendar year is a rather poor unit to
> measure time differences as it is not constant and cannot be expressed in
> seconds.
actually, it can be but depending on the frame reference used, it is either
fractions or the count varies ;)
so far we have determined in this thread that there are at least four basic sets
of routines...
calendar inclusive
calendar exclusive
fixed inclusive (existing *Span routines)
fixed exclusive (existing *Between routines)
inclusive: includes the first and last days of the period in the count. used in
(eg) rent and age calculations.
eg: Mon 01 Jul 2013 -> Fri 05 Jul 2013 = 5 day work week
Mon 01 Jul 2013 -> Sun 07 Jul 2013 = 7 day (1 week) rental
exclusive: does not count the last day of the period. used in (eg) financial
calculations.
eg: Mon 01 Jul 2013 -> Mon 08 Jul 2013 = 7 days
calendar: the difference between the date in one year and the same date in the
next or previous year is 1 year... the same with days in months... the 10th is
one month from the 10th of the previous month and one month from the 10th in the
next month no matter how many days there are in the months involved...
fixed: SI oriented counting of the length of years, months and days using
specific values for each...
The average length of a year in days is:
346.62 : a draconitic year
353,
354,
355 : common years in some lunisolar calendars
354.37 : average length of a year in lunar calendars
365 : a vague year and a common year in many solar calendars
365.24219 : mean tropical year (rounded to 5 places) for epoch 2000
365.2424 : vernal equinox year (rounded to 4 places) for epoch 2000
365.2425 : average length of a year in the Gregorian calendar
365.25 : the average length of a year in the Julian calendar
365.25636 : mean solar year
365.2564 : a sidereal year
365.25689 : a Gaussian year
366 : a leap year in many solar calendars
383,
384
385 : leap years in some lunisolar calendars.
383.9 : leap year in some lunisolar calendars.
Astronomical years count the Julian year as a unit of time, defined as 365.25
days of 86400 SI seconds each with no leap seconds.
A calendar year is an approximation of the Earth's orbital period in a given
calendar. Gregorian calendar years (as well as in the Julian calendar) has
either 365 (common years) or 366 (leap years) days.
An average Gregorian year is 365.2425 days = 52.1775 weeks = 8765.82 hours =
525949.2 minutes = 31556952 seconds (mean solar, not SI).
A common year is 365 days = 8760 hours = 525600 minutes = 31536000 seconds.
A leap year is 366 days = 8784 hours = 527040 minutes = 31622400 seconds.
The 400-year cycle of the Gregorian calendar has 146097 days and hence exactly
20871 weeks.
months are almost as bad when counting days...
27.212220 : draconic month
27.321582 : tropical month
27.321661 : sidereal month
29.53 : lunar month
29.530589 : long term average synodic month
: used to calculate eclipse cycles
30.4375 : simple 365.25 / 12 months
even using estimations, one can be off quite a bit depending on the length of
the period being measured... it can be rather embarrassing when one is
approaching the end of a countdown and everyone can easily see errors of a day
or more... witness the .5 day error in the calculations at the top of this post...
--
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