SA-MP Forums Archive
get day of week. - 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: get day of week. (/showthread.php?tid=447101)



get day of week. - audriuxxx - 28.06.2013

Hi,

How get what day is of week? sunday,monday...


Re: get day of week. - TheChimpJr - 28.06.2013

What....


Re: get day of week. - audriuxxx - 28.06.2013

What, what... I need function to get day of the week.


Re: get day of week. - Scenario - 28.06.2013

I know a function like this has been released- all you need to do is search or check the "useful functions" topic.


Re: get day of week. - Red_Dragon. - 28.06.2013

I searched for something similar to this a while ago and I got two snippets saved.
pawn Code:
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
pawn Code:
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



Re: get day of week. - Red_Dragon. - 29.06.2013

Quote:
Originally Posted by Gamer_Z
View Post
Nice piece of code but one suggestion if I may:

pawn Code:
switch(GetDayName())
{
    case 1: //Sunday
    case 2: //Monday
    case 3: //...
    case 4: //etc
    case 5: //
    case 6: //
    case 7: //
    default: //error
}
Nice thinking.