How to detect a specific day?
#5

Paste this somewhere on your script.
Note: Don't put it on callbacks.

pawn Код:
stock GetDayName(d=0,m=0,y=0) {
    /*
    0=Invalid date
    1=Sunday
    2=Monday
    ...
    7=Saturday
    */

    if(d==0&&m==0&&y==0) { //set to today if no values passed
        getdate(y, m, d);
    }

    new month[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
        i;

    if (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0))
        month[1] = 29;

    if (y < 1900 || m < 1 || m > 12 || d < 1 || d > month[m - 1])
        return 0;

    for (i = 1900; i < y; i++) {
        if (i % 4 == 0 && (i % 100 != 0 || i % 400 == 0))
            d += 366;
        else
            d += 365;
    }

    for (i = 0; i < m - 1; i++) {
        d += month[i];
    }

    return d%7+1;
}
And use this :
pawn Код:
new day=GetDayName();
if(day == 1) // Sunday
if(day == 2) // Monday
if(day == 3) // Tuesday
if(day == 4) // Wednesday
if(day == 5) // Thursday
if(day == 6) // Friday
if(day == 7) // Saturday
Reply


Messages In This Thread
How to detect a specific day? - by Tamer - 09.06.2013, 22:10
Re: How to detect a specific day? - by Vince - 09.06.2013, 22:23
Re: How to detect a specific day? - by Facerafter - 09.06.2013, 22:25
Re: How to detect a specific day? - by Tamer - 09.06.2013, 22:41
Re: How to detect a specific day? - by DeMoX - 09.06.2013, 22:41
Re: How to detect a specific day? - by Tamer - 09.06.2013, 22:44
Re: How to detect a specific day? - by Red_Dragon. - 09.06.2013, 22:56
Re: How to detect a specific day? - by DeMoX - 10.06.2013, 09:57

Forum Jump:


Users browsing this thread: 2 Guest(s)