Page 1 of 1
SOLVED - How to get someone's age from DOB and today's date
Posted: Sat Jul 30, 2011 10:07 pm
by admin12
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
Re: How to get someone's age from DOB and today's date
Posted: Sun Jul 31, 2011 6:51 am
by bangkok
Go for the Date and Time Library, from Sarah.
http://www.troz.net/rev/index.irev?cate ... ary#stacks
You'll find a function : DaysBetween, that will do the work (returns the number of days between 2 dates).
Re: How to get someone's age from DOB and today's date
Posted: Sun Jul 31, 2011 9:31 am
by wsamples
It's not so hard! You need to subtract the 4 digit birthday year from the four digit current year. Then you need to check whether or not the birth date (month and day) has been reached in the current year, and subtract a year if it hasn't. Here's an example of one way to do it
Code: Select all
-- using your stored birthday information:
-- put the birth month into tBM
-- put the birth day (of month) into tBD
-- put 4 digit birth year into tBY
-- get today's date in a format you can use:
convert the seconds to dateItems
put item 1 of it into thisYear
put item 2 of it into thisMonth
put item 3 of it into thisDay
put thisYear - tBY into trawYears
switch
case thisMonth < tBM
case (thisMonth = tBM) and (thisDay < tBD)
put trawYears - 1 into tAgeInYears
break
default
put tRawYears into tAgeInYears
end switch
-- tAgeInYears is your answer
Good luck!
Warren
Re: How to get someone's age from DOB and today's date
Posted: Sun Jul 31, 2011 4:09 pm
by admin12
wsamples wrote:It's not so hard! You need to subtract the 4 digit birthday year from the four digit current year. Then you need to check whether or not the birth date (month and day) has been reached in the current year, and subtract a year if it hasn't. Here's an example of one way to do it
Code: Select all
-- using your stored birthday information:
-- put the birth month into tBM
-- put the birth day (of month) into tBD
-- put 4 digit birth year into tBY
-- get today's date in a format you can use:
convert the seconds to dateItems
put item 1 of it into thisYear
put item 2 of it into thisMonth
put item 3 of it into thisDay
put thisYear - tBY into trawYears
switch
case thisMonth < tBM
case (thisMonth = tBM) and (thisDay < tBD)
put trawYears - 1 into tAgeInYears
break
default
put tRawYears into tAgeInYears
end switch
-- tAgeInYears is your answer
Good luck!
Warren
Warren,
Thank you. I get an error on this line:
-- get today's date in a format you can use:
convert the seconds to dateItems
How do I get the current date "in a format I can use"?
Thank you so much for your help. This is one of the things that was stopping me from getting this done.
Mike
Re: SOLVED - How to get someone's age from DOB and today's date
Posted: Sun Jul 31, 2011 5:22 pm
by wsamples
"convert the seconds to dateItems" should work, if you've typed it correctly (or copy/pasted). Could you post the error?
Try it in the message box., like this: convert the seconds to dateItems;put it