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: al:bri:xtra at: 4-Jul-2002 16:58

Joel Neely wrote:
> Good questions, to which I'll add another: > > If you were born on 29 Feb 2000, when did your next > birthday occur? > > Given the irregularities in the current calendar scheme, I guess I'd have
to wonder about the purpose of the calculation before forming opinions re date arithmetic including/surrounding leap days. Birthday parties usually occur on the same day and month each year as one's birthdate. If one is born on a leap-year day, like:
>> leap-year? 29/Feb/2000
== true then one has less birthdays than most other people. But, one can still calculate one's age as that's just the number of years, months and days that have elapsed since one's birth date.
>> now
== 4-Jul-2002/16:56:42+12:00
>> probe age now 29/Feb/2000
make object! [ Years: 2 Months: 4 Days: 5 ] Age: function [ "Calulates Age in Years, Months & Days." Date1 [date!] Date2 [date!] ] [Difference Years Months Days] [ if Date1 < Date2 [ Years: Date1 Date1: Date2 Date2: Years ] Difference: Date1 - Date2 Years: Date1/year Months: Date1/month Days: subtract Date1/day Date2/day if negative? Days [ Months: Months - 1 Days: Days + pick system/locale/days-per-month either 1 <= Months [ Months ] [ length? system/locale/days-per-month ] if all [ 2 = Months ; Previous month = February? leap-year? Date1 ] [ Days: Days + 1 ] ] Months: Months - Date2/month if negative? Months [ Years: Years - 1 Months: Months + 12 ] Years: Years - Date2/year make object! compose [Years: (Years) Months: (Months) Days: (Days)] ] Andrew Martin ICQ: 26227169 http://valley.150m.com/