Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Need code to find DayOfWeek from month/day/year

47 views
Skip to first unread message

Chris D. Bagwell

unread,
Mar 9, 1993, 6:17:37 PM3/9/93
to
Thats basically it. I need some code to find the day of week from the
month/day/year. Any language would work. Thanks

Tomohiko Sakamoto

unread,
Mar 10, 1993, 2:55:08 AM3/10/93
to
In article <cbagwell.731719057@ponder>,

cbag...@ponder.csci.unt.edu (Chris D. Bagwell) says:
> Thats basically it. I need some code to find the day of week from the
> month/day/year. Any language would work. Thanks

dayofweek(m, d, y) /* 1 <= m <= 12, y > 1752 (in the U.K.) */
{
static int t[] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 };

y -= m < 3;
return (y + y/4 - y/100 + y/400 + t[m-1] + d) % 7;
}

/*
dow(m,d,y){y-=m<3;return(y+y/4-y/100+y/400+"-bed=pen+mad."[m]+d)%7;}
This is not portable, but easy to learn by heart.
*/
--
T. Sakamoto

Stan Brown

unread,
Mar 12, 1993, 11:09:30 AM3/12/93
to
In article <1993Mar10.0...@sm.sony.co.jp> saka...@sm.sony.co.jp writes:
>In article <cbagwell.731719057@ponder>,
> cbag...@ponder.csci.unt.edu (Chris D. Bagwell) says:
>> Thats basically it. I need some code to find the day of week from the
>> month/day/year. Any language would work. Thanks
>
>dayofweek(m, d, y) /* 1 <= m <= 12, y > 1752 (in the U.K.) */
[the rest deleted]

Of course, you could always use the standard library function mktime(
).

--
Stan Brown, Oak Road Systems br...@Ncoast.ORG
Richard Harding Davis said, "I never talk about things when I don't know
the facts." Replied Oscar Wilde, "That, my dear fellow, must limit your
conversation frightfully!"

0 new messages