Thanks very much.
Malik
Please try this:
/*
* 1 <= m <= 12, y > 1752 (in the U.K.)
*/
dayofweek(y, m, d)
{
y -= m < 3;
return (y + y/4 - y/100 + y/400 + "-bed=pen+mad."[m] + d) % 7;
}
--
T. Sakamoto
Since you have crossposted in comp.lang.c I'd say that you can simply
initialize a few fields on a struct tm and then apply mktime() on it.
One of the fields will be set to the week of day.
As far as a generic formula goes, here is one I've seen a few days ago
(PASCAL-ish):
N:=(Trunc(M*2.6-0.1)+D+Y+Y div 4+5*C+C div 4) mod 7
Where:
D = day of month
Y = year of the century.
C = century.
M = Month - 2.
( January M=11 , February M=12 )
Result is an 0-6 integer.
Later,
Janos
jha...@novell.com
> Please try this:
[...]
> return (y + y/4 - y/100 + y/400 + "-bed=pen+mad."[m] + d) % 7;
You would be much better off writing "\3\0\3\2\5\0\3\5\1\4\6\2\4"
instead of "-bed=pen+mad."; that way you aren't dependent on ASCII. (I
assume ASCII is what it's intended to be used with; I didn't go testing
it.) For example, converting that string to EBCDIC, I find that it's
equivalent to "\5\4\0\6\0\4\0\2\1\1\3\6\5" then....
der Mouse