Hi Raul,

I had the same problem until I started thinking of the month in 'nominal' 
terms. So if the groundhog was born on 2012 2 2 then until 2012 3 2 it would 
not be month old. This is where the length of the different months comes in, 
but each time you go by the 2nd of the month the month count goes up by one.

Your comment did give me a reason to revisit the problem and I think I solved 
it in a slightly clearer way along the lines I do it if I am trying to figure 
it out in my head. I figure out the difference in years, then months (depending 
on whether the current day is before after the day of the event) and finally 
the difference between the days modulo the length of the month. I also found 
out that todayno handles leap years by having the same value for yy 2 29 as yy 
3 1 if it not a leap year, so that means that my leap year adjustment is as 
accurate as todayno.

Cheers, bob

ymda =: 3 : 0 NB. elapsed time: x is today, y is birthdate
'left argument is reference date ; right argument is event date'
:
bnum =:todayno 'yb mb db'=:bday =: y
tnum =:todayno 'yt mt dt'=:today =: x
if. tnum < bnum do. 'Wasn''t born yet!' return. end.
lbnum=:todayno 'ylb mlb dlb'=:lbday=:(yb - tnum (0>-) bnum)(0)}bday  NB. bnum 
of last birthday from today
leapa=: ((leapnum>:bnum)*(leapnum<tnum))*(todayno ylb,3 1) - leapnum=:todayno 
yb,2 29 NB. Feb 29 within interval
dcount=:  31,(28 + leapa ), 31 30 31 30 31 31 30 31 30 31 NB. month durations 
(yt-ylb),((12|mt-mb)-dt<db),((<:<:mt){dcount )|dt-db NB. result in yy mm dd
)

   2000 3 26 ymda 2000 2 27
0 0 28
   1999 3 26 ymda 1999 2 27
0 0 27
   2000 1 26 ymda 2000 2 27
Wasn't born yet!
   2001 1 26 ymda 2000 2 27
1 10 30
   2001 1 27 ymda 2000 2 27
1 11 0

On Sep 21, 2014, at 12:36 AM, Raul Miller <[email protected]> wrote:

> I can't make sense of mixing days from the two months and combining
> them to get a month because we do not know how long that month is. I
> do not know how long Febember should be. I'd run into a similar issue
> if the date range started and ended in Februrary and only one of them
> was from a leap year.

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

Reply via email to