Age Calculate
#2

The easy way: create a function to transform the date into a number:

pawn Код:
// @UNTESTED
// Number of days in the given month, no leap years
new daysInMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

stock GetDateIndex(day, month, year)
{
    // Presume 365 days a year
    new index = year * 365 + day;
    // Add the days of the months that already passed
    for (new i = 0; i < month; i++) index += daysInMonth[i];
    return index;
}
Do this for the current date, and for the birthdate, subtract them, and divide it by 365 and you got the approximated age.

The hard way: Do the same as above, but add the rules for leap years etc to get the exact number of days.
}
Reply


Messages In This Thread
Age Calculate - by Marco940 - 30.06.2012, 11:23
Re: Age Calculate - by Mauzen - 30.06.2012, 11:31
AW: Age Calculate - by Nero_3D - 30.06.2012, 14:19

Forum Jump:


Users browsing this thread: 1 Guest(s)