Ah, but if the OP wants an answer in the form "the person is X years old today," that's where the problem arises. A good edge case is:
Birthday: 2/28/2000 Today: 2/27/2001 With the getTime() approach, new Date("2/27/2001").getTime() - new Date("2/28/2000").getTime() gives 31536000000 (Jan 1, 1971 UTC), or 365 days. In this case the age is not 1 though, because that year was 366 days instead of 365. That's why I would still choose to do the calculation without getTime(), and why I don't think those doc examples are particularly good ones - a day is not always 24 hours, a year is not always 365 days, etc. And sorry for beating a dead horse so badly! :) --- In flexcoders@yahoogroups.com, "Tracy Spratt" <[EMAIL PROTECTED]> wrote: > > Oops, yes, the subtraction should be reversed. > > > > But one of the overloads of the Date constructor takes a single > argument, the number of milliseconds from the reference date, the same > reference date as the getTime() method. The doc example shows this > method for adding time to a date, but I expect it will work for > subracting time as well. > > > > Tracy > > > > ________________________________ > > From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On > Behalf Of Doug Lowder > Sent: Tuesday, October 02, 2007 3:37 PM > To: flexcoders@yahoogroups.com > Subject: [flexcoders] Re: Return a person's age > > > > Wouldn't that produce a negative number, given that birthDate > probably comes before todayDate? > > Discounting that, I think that would give you the person's age in > milliseconds. > > --- In flexcoders@yahoogroups.com <mailto:flexcoders% 40yahoogroups.com> > , "Tracy Spratt" <tspratt@> wrote: > > > > Based on my reading of the docs, there is a simpler way: > > > > var age = new Date(birthDate.getTime() - todayDate.getTime); > > > > Untested. > > > > Tracy > > > > ________________________________ > > > > From: flexcoders@yahoogroups.com <mailto:flexcoders% 40yahoogroups.com> > > [mailto:flexcoders@yahoogroups.com <mailto:flexcoders% 40yahoogroups.com> > ] On > > Behalf Of JRBower > > Sent: Tuesday, October 02, 2007 2:29 AM > > To: flexcoders@yahoogroups.com <mailto:flexcoders% 40yahoogroups.com> > > Subject: Re: [flexcoders] Return a person's age > > > > > > > > > > Doug, > > Thank you. I will give your code a go. :) > > > > Best Regards, > > James > > > > Doug Lowder wrote: > > > > > > Here's how I would do it: > > > > > > var age:Number = todayDate.fullYear - birthDate.fullYear; > > > if (todayDate.month < birthDate.month || (todayDate.month == > > > birthDate.month && todayDate.date < birthDate.date)) age--; > > > return age; > > > > > > > > > > -- > > View this message in context: > > http://www.nabble.com/Return-a-person%27s-age- > <http://www.nabble.com/Return-a-person%27s-age-> > tf4545118.html#a12993386 > > <http://www.nabble.com/Return-a-person%27s-age- > <http://www.nabble.com/Return-a-person%27s-age-> > tf4545118.html#a12993386> > > > > Sent from the FlexCoders mailing list archive at Nabble.com. > > >