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: 5-Jul-2002 9:38

Ladislav wrote:
> you probably missed my suggested change.
I did too! Sorry.
> AFAICT your function can yield negative days sometimes.
You're right! I tried out comparing date with date from 1/1/1900 to 1/1/2000 and discovered that: Age 30/01/1900 01/03/1900 ; My 'Age NOT Ladislav's age. gives a negative day. So I decided to replace my age value with your age value. Thank you, Ladislav! My 'Age function now looks like: Age: function [ "Calulates Age in Years, Months & Days." Birth [date!] Date [date!] ] [Years Months Days New] [ if Date < Birth [ return Age Date Birth ] Days: Date/day - Birth/day if negative? Days [ Months: Birth/month + 1 Years: Birth/year if Months > 12 [ Months: 1 Years: Years + 1 ] New: to date! reduce [1 Months Years] Days: New - Birth + Date/day - 1 Birth: New ] Months: Date/month - Birth/month Years: Date/year - Birth/year if negative? Months [ Months: Months + 12 Years: Years - 1 ] make object! compose [Years: (Years) Months: (Months) Days: (Days)] ] And if people are interested in some tests: 26/10/2002 25/10/1960 [Years: 42 Months: 0 Days: 1] 25/10/2002 25/10/1960 [Years: 42 Months: 0 Days: 0] 24/10/2002 25/10/1960 [Years: 41 Months: 11 Days: 30] 01/03/2005 29/02/2004 [Years: 1 Months: 0 Days: 1] 28/02/2005 29/02/2004 [Years: 0 Months: 11 Days: 28] 02/03/2004 29/02/2004 [Years: 0 Months: 0 Days: 2] 01/03/2004 29/02/2004 [Years: 0 Months: 0 Days: 1] 29/02/2004 29/02/2004 [Years: 0 Months: 0 Days: 0] 01/03/2004 29/02/2000 [Years: 4 Months: 0 Days: 1] 29/02/2004 29/02/2000 [Years: 4 Months: 0 Days: 0] 30/01/1900 01/03/1900 [Years: 0 Months: 1 Days: 2] Thanks again, Ladislav! Andrew Martin ICQ: 26227169 http://valley.150m.com/