Getting someone's age from dob and current year

Roger Eller roger.e.eller at sealedair.com
Sat Jul 30 20:16:44 EDT 2011


On Sat, Jul 30, 2011 at 5:20 PM, Admin wrote:

>
>
> Hello all,
>
> I need to figure out someone's age.
>
> I have their date
> of birth and I have today's date. How do I get the end result. My math
> skills SUCK.
>
> Here's my code (loaded in from the database with a SELECT
> statement):
>
> put item 7 of myLine into dobMonth
> put item 8 of myLine
> into dobDay
> put item 9 of myLine into dobYear
> put chartonum("dobYear")
> into dobYearNum
> put the long system date into field "TodayDate"
>
> I
> figured I would subtract this year from the dobyear and get the age - am
> I right? How would I do this if I am?
>
> Mike
>

Hey Mike, put this into a new button object.

on mouseUp
   put the date into tToday
   ask "Enter the date of birth as dd/mm/yy"
   put it into tBorn
   convert tToday to seconds
   convert tBorn to seconds
   put (tToday - tBorn) into tAge -- in seconds
   -- now do the math in tAge
   -- to determine how many years that is
   answer "The age is" && tAge && "seconds old." & cr & cr \
          & "You didn't expect me to do all of the math, now did you? :)"
end mouseUp

˜Roger



More information about the use-livecode mailing list