Many thanks for all the suggestions - and I did learn a couple of new tricks 
from your code, too! I had not realised that there could be an issue with 
pre-1970 dates in Windows, and also did not know that we had to watch out for 
the 'centuryCutoff' property. Very, very useful to know.

Peter's code seems to be the most succinct - and flexible - for calculating the 
age:

On 22/05/2012, at 6:01 AM, Peter M. Brigham, MD wrote:

> function doAge tDate,asOf
>   -- returns the age given birthdate = <tDate>
>   -- as of the date <asOf> (if empty, assumes today)
>   if tDate = empty then return empty
>   if asOf = empty then
>      put the date into asOf
>   end if
>   set the itemdelimiter to "/"
>   put item -1 of the short date into nowYr
>   set the centurycutoff to nowYr+1
>   set the itemdelimiter to comma
>   convert tDate to dateItems
>   convert asOf to dateitems
>   put item 1 of asOf - item 1 of tDate - 1 into tAge
>   put item 1 of asOf into item 1 of tDate
>   convert tDate to seconds
>   convert asOf to seconds
>   if tDate <= asOf then add 1 to tAge
>   return tAge
> end doAge

This, however, does not seem to handle the 'before 1970' problem in Windows - 
ie., 'convert tDate to dateItems' here should fail in Windows, if tDate is 
before 1970. Is that correct, or am I missing something obvious?

--
Igor Couto
Sydney, Australia


_______________________________________________
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

Reply via email to