How to know the day of the week?
#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


Messages In This Thread
How to know the day of the week? - by x-cutter - 22.02.2009, 20:26
Re: How to know the day of the week? - by MenaceX^ - 23.02.2009, 14:06
Re: How to know the day of the week? - by yom - 23.02.2009, 14:34
Re: How to know the day of the week? - by x-cutter - 23.02.2009, 14:42
Re: How to know the day of the week? - by yom - 23.02.2009, 15:07
Re: How to know the day of the week? - by x-cutter - 23.02.2009, 15:12

Forum Jump:


Users browsing this thread: 1 Guest(s)