SA-MP Forums Archive
Help Needed - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Help Needed (/showthread.php?tid=576549)



Help Needed - hamzajaved780 - 05.06.2015

How can i calculate a player's current age using the birthdate string

PHP код:
"YYYY-MM-DD" 



AW: Help Needed - Kaliber - 05.06.2015

With this function:

But first, switch the strings to: DD-MM-YYYY

PHP код:
stock const g_days_m[12] = {312831303130313130313031};
stock GetPlayerAge(input[]) //©Jeffry
{
    new 
date[12];
    
strcat(dateinput);
    if(
date[1] == '.'strins(date"0"012);
    if(
date[4] == '.'strins(date"0"312);
    if(!
date[9] || date[10]) return -1;
    new 
day 10*(date[0]-48)+(date[1]-48);
    new 
month 10*(date[3]-48)+(date[4]-48);
    new 
year 1000*(date[6]-48)+100*(date[7]-48)+10*(date[8]-48)+(date[9]-48);
    if(
year 1000 || year 9999 || month || month 12 || day 1) return -1;
    if(
month == 2)
    {
        if(
day 28 && (year != || (year 100 == && year 400 != 0))) return -1;
    }
    else if(
day g_days_m[month-1]) return -1;
    new 
dmy;
    
getdate(ymd);
    new 
age year;
    if(
monthage--;
    else if(
== month && dayage--;
    return (
age 0) ? (-1) : (age);

If it returns -1...then the age is invalid, else it returns the age


Re: Help Needed - hamzajaved780 - 05.06.2015

I cant switch the format as i have hundreds of users saved with this.
Can you please recode it for me.