30.06.2012, 11:31
The easy way: create a function to transform the date into a number:
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.
}
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;
}
The hard way: Do the same as above, but add the rules for leap years etc to get the exact number of days.
}