Calculating age given DOB-PIC maths

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
nmindana
Posts: 82
Joined: Thu Nov 18, 2010 5:00 pm
Has thanked: 52 times
Been thanked: 5 times
Contact:

Calculating age given DOB-PIC maths

Post by nmindana »

Hi,

I am trying to formulate an age calculator, where in if you input your date of birth, it outputs your age in days.
Can anybody help me with some ideas or a simple programme ?. :(

many thanks

Indana

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: Calculating age given DOB-PIC maths

Post by Spanish_dude »

It's not that difficult to do, assuming the PIC knows which day, month and year we are "today".

I'd probably do something like this:

Code: Select all

char age, month, day, input_month, input_day;
short year, input_year;

// year, month and day is given by a RTC (?)
// input_year, input_month and input_day is given by the user

age = year - input_year - 1;

if ((month - input_month) > 0)     // if (month - input_month) is higher than 0
{
    age = age + 1; // add 1 to age
}
else if (month == input_month) // if the given month is equal to the month given by the RTC
{ 
    if ((day - input_day) >= 0) // and if (day - input_day) is higher or equal to 0
    {
        age = age + 1; // add 1 to age
    }
}
BR,

Nicolas

Post Reply