Age Calculation

User Help for GS-Base

Age Calculation

Postby CRK » Wed Oct 15, 2014 4:00 pm

Hello:

Can someone explain to me how I might calculate a persons age, given their birthdate and the current date. Any help would be appreciated.
CRK
 
Posts: 2
Joined: Tue Jul 26, 2011 3:20 pm

Re: Age Calculation

Postby citadel5 » Wed Oct 22, 2014 11:30 am

To calculate the precise date difference you should use the dateDiff() function, which will return the exact number of days.

Regarding the "age" value as such it'll depend on how you would like to calculate full years. Assuming that your "age" changes just after the birth anniversary, you can use something like that (one line):

=year(today()) - year(date) - if(month(date) < month(today()), 0, if(month(date) > month(today()), 1, day(date) >= day(today())))

Use this formula for the "age" field, choosing the "Calculation formula" option in the "Special" section of the "Field Setup" dialog box. Once you enter the formula in that section, use the "Tools > Update All... (F9)" command to calculate this field for all already entered records.

If the "date" field is not a valid GS-Base date field (that is, a text field containing optionally formatted generic date/time YYYY-MM-DD strings), the above "date" argument should be replaced by dateValue(date).

If the date strings include the time (hour/minute) value, another nested if() should be added.
User avatar
citadel5
 
Posts: 119
Joined: Tue Apr 20, 2010 11:58 pm

Re: Age Calculation

Postby CRK » Sun Mar 15, 2015 11:06 pm

Many thanks




citadel5 wrote:To calculate the precise date difference you should use the dateDiff() function, which will return the exact number of days.

Regarding the "age" value as such it'll depend on how you would like to calculate full years. Assuming that your "age" changes just after the birth anniversary, you can use something like that (one line):

=year(today()) - year(date) - if(month(date) < month(today()), 0, if(month(date) > month(today()), 1, day(date) >= day(today())))

Use this formula for the "age" field, choosing the "Calculation formula" option in the "Special" section of the "Field Setup" dialog box. Once you enter the formula in that section, use the "Tools > Update All... (F9)" command to calculate this field for all already entered records.

If the "date" field is not a valid GS-Base date field (that is, a text field containing optionally formatted generic date/time YYYY-MM-DD strings), the above "date" argument should be replaced by dateValue(date).

If the date strings include the time (hour/minute) value, another nested if() should be added.
CRK
 
Posts: 2
Joined: Tue Jul 26, 2011 3:20 pm


Return to GS-Base Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron