Quote:
Originally Posted by Gammix
PHP код:
numdays(year, month) {
switch (month) {
case 4, 6, 9, 11: {
return 30;
}
case 2: {
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
return 29;
}
return 28;
}
}
return 31;
}
getage(birth_year, birth_month, birth_day) {
new current_year, current_month, current_day;
getdate(current_year, current_month, current_day);
new sum;
new cumulative_days[12];
for (new i = 0; i < 12; ++i){
sum += numdays(current_year, i);
cumulative_days[i] = sum;
}
new age = (current_year - birth_year - 1);
new days_this_year = (current_day + cumulative_days[current_month - 1]);
new days_birth_year = (cumulative_days[11] - (birth_day + cumulative_days[birth_month - 1]));
new total_days = (days_this_year + days_birth_year);
age += total_days/365;
return age;
}
// how to use
printf("Age: %i", getage(1995, 6, 30));
|
Your code works perfect but only when defining the day, month and year.
My code:
pawn Код:
enum pInfo
{
pBirthDate[24]
};
new PlayerInfo[MAX_PLAYERS][pInfo];
//Load variable
pawn Код:
cache_get_value_name(0, "Birthdate", PlayerInfo[extraid][pBirthDate],24);
//To modify the variable
pawn Код:
format(PlayerInfo[playerid][pBirthDate], 24, inputtext);
How can I use your function like this?
Thanks for you time!.