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

Date -> Day of week conversion

370 views
Skip to first unread message

Ijaz Rashid Malik

unread,
Dec 11, 1992, 7:48:19 AM12/11/92
to

Could someone please forward me algorithm to convert the date (in dd.mm.yy
or yy.mm.dd format, but assume individual fields can be obtained as integers)
to corresponding day of the week.

Thanks very much.

Malik

Tomohiko Sakamoto

unread,
Dec 14, 1992, 9:18:18 PM12/14/92
to
In article <Bz3I8...@ccu.umanitoba.ca>,

umm...@ccu.umanitoba.ca (Ijaz Rashid Malik) says:
>
> Could someone please forward me algorithm to convert the date (in dd.mm.yy
> or yy.mm.dd format, but assume individual fields can be obtained as integers)
> to corresponding day of the week.

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

Janos A. Haide

unread,
Dec 11, 1992, 3:03:10 PM12/11/92
to

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

der Mouse

unread,
Dec 17, 1992, 5:09:41 PM12/17/92
to
In article <1992Dec15.0...@sm.sony.co.jp>, saka...@sm.sony.co.jp (Tomohiko Sakamoto) writes:
> In article <Bz3I8...@ccu.umanitoba.ca>, umm...@ccu.umanitoba.ca (Ijaz Rashid Malik) says:
>> Could someone please forward me algorithm to convert the date
>> ([...]) to corresponding day of the week.

> 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

mo...@larry.mcrcim.mcgill.edu

อับดุล

unread,
Oct 10, 2023, 1:38:09 AM10/10/23
to
ในวันที่ วันศุกร์ที่ 18 ธันวาคม ค.ศ. 1992 เวลา 5 นาฬิกา 09 นาที 41 วินาที UTC+7 der Mouse เขียนว่า:
slots https://tryplayingslots.com
0 new messages