[solved]getting the day of the week
Posted: Sun Dec 16, 2007 12:34 pm
i'm trying to figure out the day of the week using the information for this page http://en.wikipedia.org/wiki/Calculatin ... f_the_week
here's my code
this code always returns 0 instead of the right number
here's my code
Code: Select all
unsigned char days_table[]={0,1,2,3,4,5,6};
unsigned char months_table[]={0,0,3,3,6,1,4,6,2,5,0,3,5};
unsigned char months_table_leap[]={0,6,2,3,6,1,4,6,2,5,0,3,5};
void get_week_day(void)
{
unsigned short num;
num+=year;
num+=year/4;
if(year%4==0)
{
num+=months_table_leap[month];
}
else
{
num+=months_table[month];
}
num+=day;
num=num%7;
week_day=(unsigned char)num;
}