MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: ,Date calculating software?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg30445] Re: [mg30414] ,[mg30390] Date calculating software?
  • From: Ranko Bojanic <bojanic at math.ohio-state.edu>
  • Date: Tue, 21 Aug 2001 03:05:26 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com




In a message dated 2001/8/15 1:06:37 AM,"Noz"<NOSPAM at austracom.nz> writes:
    > Is there a software program or calculator available that can eg.Add a
    > period of time to a date?
  
    > example,today is 14 August 2001.
    >14082001+18 months
    > or
    >14082001+1yr,3mths,4 days,and produces the date 1yr,3mths and 4 days
    > hence?

As several readers have pointed out, the package Miscellaneous`Calendar`
contains the function DaysPlus[{y,m,d}, nd] which gives the date nd days 
away from {y, m, d}. So the simplest solution of the problem of adding 
two dates  {y1,m1,d1} and {y2, m2, d2} would be to convert {y2, m2, d2}
into days and use the function DaysPlus.
 
A solution by Bob Hanlon, based on that idea,

daysPlus[date_, n_]:=
     DaysPlus[date, Ceiling[n/.{year ->365.25,month ->365.25/12, day ->1}]]

unfortunately does not give correct results in many cases. We have, for 
instance,

daysPlus[{2000, 1, 1}, 1 year]
{2001,1,1}

which is correct because the year 2000 is a leap year and Ceiling[365.25]=366.
On the other hand

daysPlus[{2001, 1, 1}, 1 year]
{2002, 1, 2}

is not correct because the year 2001 has 365 days and  Ceiling[365.25]=366. 
If we have a date {y, m, d} and we add 1 year to that date, we
expect to have the date {y+1, m, d}, regardless of the actual length of the 
year. A solution along these lines,  by Tom Burton,

DatePlus[{y_, m_, d_},{yy_, mm_, dd_}]:=
           DaysPlus[{y+yy+Quotient[m+mm,12,1], Mod[m+mm,12, 1],d}, dd]
           
gives correct results:

DatePlus[{2001, 1, 1},{1, 0, 0}]
{2002,1,1}
DatePlus[{2000, 1, 1},{1, 0, 0}]
{2001,1,1}

It is instructive to apply both formulas to the year 1752 when the calendar 
was reformed in the English speaking countries:

daysPlus[{1752, 1, 1}, 1 year]
{1753, 1, 12}
DaysBetween[{1753, 1, 12},{1752, 1, 1}]
366

DatePlus[{1752, 1, 1},{1, 0 ,0}]
{1753,1,1}
DaysBetween[{1753, 1, 1},{1752, 1, 1}]
355

Since the formula daysPlus[{y, m, d}, 1 year] gives the correct result 
{y+1, m, d} only if y is a leap year, which has 366 days, it would give 
a correct result in this case too  if 11 days were not  dropped from the 
year 1752. Mathematica software is clearly aware of these 11 days:

DaysPlus[{1752, 9, 2}, 1]
{1752, 9, 14}

Regards,
Ranko



  • Prev by Date: Re: How to do a simple loop?
  • Next by Date: Mathematica for Mac OS X
  • Previous by thread: Re: third vert axis
  • Next by thread: Mathematica for Mac OS X