Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Re: How to...? Convert Date of Birth to Age

From: greggirwin:mindspring at: 2-Jul-2002 17:40

Hi Andrew, << Using Rebol (of course!), how would I convert a date of birth to an age in years, months and days? >> Well, it's not exactly what you asked for, but it's a start. Maybe I'll mod it later tonight. (watch for wrap) days-between: func [date-1[date!] date-2[date!]][ return date-1 - date-2 ] persons-age: func [ "Return a persons age, in years." b-day [date!] /precise "Include decimal portion of age." /days "Return result as how many *days* old the person is." /yrs-days "Return result as number of years and days (2 item block)." /on "Use alternate date instead of current date, to figure age." date /local result ][ date: any [date now] if days [return days-between date b-day] if precise [return (days-between date b-day) / 365.25] if yrs-days [return compose [(to-integer date - b-day / 365.25)(date - b-day // 365.25)]] ; otherwise, take away 1 year if their birthday hasn't come yet this year. return date/year - b-day/year - either any [ (date/month > b-day/month) all [ (date/month = b-day/month)(date/day >= b-day/day)]] [0][1] ] persons-age 23-dec-1964 persons-age/days 23-dec-1964 persons-age/yrs-days 23-dec-1964 persons-age/precise 23-dec-1964 persons-age/on-date 23-dec-1964 23-dec-2001 --Gregg