get day of week.
#1

Hi,

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

What....
Reply
#3

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

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

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
Reply
#6

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)