How to know the day of the week?
#1

How can my script detect what day of the week it is?
like Sunday, Monday, Tuesday, etc

Thanks
Reply
#2

gettime function.
example:
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
  new day,month,year,hour,mins,sec,string[128];
  gettime(hour,mins,sec);
  getdate(day,month,year);
  if(!strcmp(cmd,"/time",true))
  {
    format(string,sizeof(string),"The date is now: %d/%d/%d, The time is now: %d:%d:%d",day,month,year,hour,mins,sec);
    SendClientMessage(playerid,0xFFFFFFAA,string);
    return true;
  }
return false;
}
Reply
#3

Can't you read the first post before posting? He want weekdays. Also it's cmdtext not cmd.

X Cutter, download Pawn and look in the examples folder.
Reply
#4

Quote:
Originally Posted by 0rb
Can't you read the first post before posting? He want weekdays. Also it's cmdtext not cmd.

X Cutter, download Pawn and look in the examples folder.
Pawn? Do you mean the server package? Or Pawno?

I searched for Pawn on ****** and it turned me over a chess game... -.-'
Reply
#5

I've just made that, based on Pawn's example, but can't test, tell me if it works or not. If it works i'll improve it.

pawn Код:
GetWeekDay(day=0, month=0, year=0)
{
  if (!day)
    getdate(year, month, day);

  new
    weekday_str[10],
    j,
    e
  ;

  if (month <= 2)
  {
    month += 12;
    --year;
  }

  j = year % 100;
  e = year / 100;

  switch ((day + (month+1)*26/10 + j + j/4 + e/4 - 2*e) % 7)
  {
    case 0: weekday_str = "Saturday";
    case 1: weekday_str = "Sunday";
    case 2: weekday_str = "Monday";
    case 3: weekday_str = "Tuesday";
    case 4: weekday_str = "Wednesday";
    case 5: weekday_str = "Thursday";
    case 6: weekday_str = "Friday";
  }

  return weekday_str;
}
Usage
pawn Код:
GetWeekDay(); //should return the weekday of today
GetWeekDay(13, 3, 2009); //should return "Friday"
Wow 4444 posts
Reply
#6

Quote:
Originally Posted by 0rb
I've just made that, based on Pawn's example, but can't test, tell me if it works or not. If it works i'll improve it.

pawn Код:
GetWeekDay(day=0, month=0, year=0)
{
  if (!day)
    getdate(year, month, day);

  new
    weekday_str[10],
    j,
    e
  ;

  if (month <= 2)
  {
    month += 12;
    --year;
  }

  j = year % 100;
  e = year / 100;

  switch ((day + (month+1)*26/10 + j + j/4 + e/4 - 2*e) % 7)
  {
    case 0: weekday_str = "Saturday";
    case 1: weekday_str = "Sunday";
    case 2: weekday_str = "Monday";
    case 3: weekday_str = "Tuesday";
    case 4: weekday_str = "Wednesday";
    case 5: weekday_str = "Thursday";
    case 6: weekday_str = "Friday";
  }

  return weekday_str;
}
Usage
pawn Код:
GetWeekDay(); //return the weekday of today
GetWeekDay(13, 3, 2009); //return "Friday"
Wow 4444 posts
omfg 4444

Lol thanks, I'll try and post/edit after.

EDIT : Well it looks like it worked, returned monday :P

I did some little editing, to make it return a value instead of a str, so it fits my script, I hope you don't mind.

Thanks alot

- X Cutter
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)