Calculating age

Share business templates, ideas, experiences, etc with fellow Servoy developers here

Calculating age

Postby Andy » Fri May 25, 2007 1:53 pm

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')
}
nav
Andy
 
Posts: 32
Joined: Wed Apr 18, 2007 9:26 pm
Location: Suriname

Postby pbakker » Fri May 25, 2007 2:00 pm

Why do you start with "return;"

That ends the calc immediatly...
pbakker
 
Posts: 2822
Joined: Wed Oct 01, 2003 8:12 pm
Location: Amsterdam, the Netherlands

Postby sanneke » Fri May 25, 2007 2:04 pm

it should be something like this

Code: Select all
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
Sanneke
Yield Software Development: Need help on your project?
yieldsd.com
User avatar
sanneke
 
Posts: 383
Joined: Thu Jun 15, 2006 9:20 am
Location: Amersfoort

Postby Andy » Fri May 25, 2007 2:45 pm

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
nav
Andy
 
Posts: 32
Joined: Wed Apr 18, 2007 9:26 pm
Location: Suriname

Postby sanneke » Fri May 25, 2007 3:02 pm

You should use getDate() instead of getDay(). getDay() gets the day of the week and getDate() the date of the month
Sanneke
Yield Software Development: Need help on your project?
yieldsd.com
User avatar
sanneke
 
Posts: 383
Joined: Thu Jun 15, 2006 9:20 am
Location: Amersfoort

Postby sanneke » Fri May 25, 2007 3:21 pm

Actually the if statement should be:

Code: Select all
if ((birtdate.getMonth() < globals.action_date.getMonth()) || (birtdate.getDate() < globals.action_date.getDate() && birtdate.getMonth() == globals.action_date.getMonth()))
Sanneke
Yield Software Development: Need help on your project?
yieldsd.com
User avatar
sanneke
 
Posts: 383
Joined: Thu Jun 15, 2006 9:20 am
Location: Amersfoort

Postby Andy » Fri May 25, 2007 3:35 pm

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
nav
Andy
 
Posts: 32
Joined: Wed Apr 18, 2007 9:26 pm
Location: Suriname

Postby sanneke » Fri May 25, 2007 3:45 pm

My mistake it should be

Code: Select all
if ((birtdate.getMonth() > globals.action_date.getMonth()) || (birtdate.getDate() > globals.action_date.getDate() && birtdate.getMonth() == globals.action_date.getMonth()))
[/code]
Sanneke
Yield Software Development: Need help on your project?
yieldsd.com
User avatar
sanneke
 
Posts: 383
Joined: Thu Jun 15, 2006 9:20 am
Location: Amersfoort

Postby Andy » Fri May 25, 2007 4:17 pm

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
nav
Andy
 
Posts: 32
Joined: Wed Apr 18, 2007 9:26 pm
Location: Suriname

Postby sanneke » Fri May 25, 2007 4:47 pm

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.
Sanneke
Yield Software Development: Need help on your project?
yieldsd.com
User avatar
sanneke
 
Posts: 383
Joined: Thu Jun 15, 2006 9:20 am
Location: Amersfoort

Postby Andy » Mon May 28, 2007 1:19 pm

OK,

Thank you

Andy
nav
Andy
 
Posts: 32
Joined: Wed Apr 18, 2007 9:26 pm
Location: Suriname


Return to Sharing Central

Who is online

Users browsing this forum: No registered users and 4 guests

cron