On Jun 26, 2014, at 10:44 PM, Mark Smith wrote: > Hi, does anyone know how to calculate someones age in years from two dates? > > Currently I am doing something kludgy like: > > convert dateone from date to seconds > convert datetwo from date to seconds > put datetwo - dateone into age -- calculate the age in seconds > -- divide by the number of seconds per year > put 60*60*24*365.25 into secs_per_year > put the trunc of (age / secs_per_year) into age > > But I suspect it is only approximate. > > Thanks
Here's the handler that I use: function doAge birthDate,asOf -- return the age given birthdate = <birthDate> -- as of the date <asOf> (if empty, assumes today) if asOf = empty then put the date into asOf end if convert birthDate to dateItems put item 1 of birthDate into birthYear convert asOf to dateitems put item 1 of asOf - birthYear - 1 into tAge if tAge < 0 then add 100 to tAge put item 1 of asOf into item 1 of birthDate convert birthDate to seconds convert asOf to seconds if birthDate <= asOf then add 1 to tAge return tAge end doAge -- Peter Peter M. Brigham pmb...@gmail.com http://home.comcast.net/~pmbrig _______________________________________________ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode