Calculating age

Hi there,

I made a calculation for a field called age but it does not work properly can you help me out?

if the birthdate has not passed substract a year it should take one year of but this is not the case please advise.

Thank you

return; if(getDay(birtdate)< getDay(globals.action_date) &&
getMonth(birtdate)<= getMonth(globals.action_date))
{utils.dateFormat(globals.action_date, ‘yyyy’) -
utils.dateFormat(birtdate, ‘yyyy’)-1}
else
{utils.dateFormat(globals.action_date, ‘yyyy’) -
utils.dateFormat(birtdate, ‘yyyy’)
}

Why do you start with “return;”

That ends the calc immediatly…

it should be something like this

var age 

if(birtdate.getDate() < globals.action_date.getDate() && birtdate.getMonth()<= globals.action_date.getMonth())
{
	age = globals.action_date.getFullYear() - birtdate.getFullYear() -1 
}
else
{
	age = globals.action_date.getFullYear() - birtdate.getFullYear()
}

return age

Thank you,

the final one is:

var age

if(birtdate.getDay() < globals.action_date.getDay() && birtdate.getMonth()>= globals.action_date.getMonth())
{
age = globals.action_date.getFullYear() - birtdate.getFullYear() -1
}
else
{
age = globals.action_date.getFullYear() - birtdate.getFullYear()
}

return age

You should use getDate() instead of getDay(). getDay() gets the day of the week and getDate() the date of the month

Actually the if statement should be:

if ((birtdate.getMonth() < globals.action_date.getMonth()) || (birtdate.getDate() < globals.action_date.getDate() && birtdate.getMonth() == globals.action_date.getMonth())) 

I tried the code and it does not work

I think you need the day of the week because, Lets say is someone birthdate is the 20th of january on the 19th he is still age -1

Randy

My mistake it should be

if ((birtdate.getMonth() > globals.action_date.getMonth()) || (birtdate.getDate() > globals.action_date.getDate() && birtdate.getMonth() == globals.action_date.getMonth()))

[/code]

Ok This one works.

Please explain to me why this one is better than mine.

I am new to java and I am thinking FileMaker.

Thank you

Randy

Say the action_date is today and the person is born in 1981 11 th of july
then your calculation will say the person is 26, actualy he is 25 .

Try to understand my if statement.

I don’t think this is that different in filemaker. If’s are everywhere the same.

OK,

Thank you

Andy