On 4/8/07, Brian Schott <[EMAIL PROTECTED]> wrote:
        In casual conversation we talk about how far apart
our birthdays are...

Perhaps this one is worth considering.

days=: 31 28 31 30 31 30 31 31 30 31 30 31
datediff=: 4 : 0
 'm d'=. y-x
 (12|m-d<0), d+(days{~12|2-~{.y)*d<0
)

Examples:
  a=. 11 5   NB. Nov 5
  b=. 1 19   NB. Jan 19
  a datediff b
2 4    NB. 2 months 4 days from a to b
  b datediff a
9 17  NB. 9 months 17 days from b to a
  3 25 datediff 6 25
3 0   NB. 3 months from Mar 25 to the same date in June

Of course, there still remains the need to deal with leap
years properly, but I am too lazy to do that :)

Regards,
  Boyko
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to