How to obtain age from date of birth?
#7

Quote:
Originally Posted by Gammix
Посмотреть сообщение
PHP код:
numdays(yearmonth) {
    switch (
month) {
        case 
46911: {
            return 
30;
          }
        case 
2: {
            if ((
year == && year 100 != 0) || (year 400 == 0)) {
                return 
29;
            }
            return 
28;
          }
    }
    
    return 
31;
}
getage(birth_yearbirth_monthbirth_day) {
    new 
current_yearcurrent_monthcurrent_day;
    
getdate(current_yearcurrent_monthcurrent_day);
    new 
sum;
    new 
cumulative_days[12];
    for (new 
012; ++i){
        
sum += numdays(current_yeari);
        
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(1995630)); 
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!.
Reply


Messages In This Thread
How to obtain age from date of birth? - by Jose_grana - 11.08.2018, 23:44
Re: How to obtain age from date of birth? - by Jefff - 12.08.2018, 00:25
Re: How to obtain age from date of birth? - by Gammix - 12.08.2018, 01:13
Re: How to obtain age from date of birth? - by Jefff - 12.08.2018, 01:30
Re: How to obtain age from date of birth? - by Private200 - 12.08.2018, 02:18
Re: How to obtain age from date of birth? - by CaptainBoi - 12.08.2018, 03:38
Re: How to obtain age from date of birth? - by Jose_grana - 12.08.2018, 23:13
Re: How to obtain age from date of birth? - by Gammix - 13.08.2018, 01:08

Forum Jump:


Users browsing this thread: 1 Guest(s)