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

OT; looking for a "day of the week" algorithm THAT WORKS...

0 views
Skip to first unread message

mcalhoun

unread,
Aug 19, 2003, 4:38:17 PM8/19/03
to
I've seen several algorithms which calculate the day-of-the-week (usually
0=Sunday, 1=Monday, ... 6=Saturday), but I've NEVER found one that works
for all cases (I test them against the UNIX "cal"). For example, the
Summer, 1999, Tau Beta Pi magazine had an article by Howard L. Benford
which said (paraphrasing):

---------- cut here ---------- cut here ---------- cut here ----------
Given a date in the usual "M/D/Y" form, the day of the week (DotW) can
be calculated as an integer from 0 through 6 representing Sunday through
Saturday, respectively:

{INT (1.25 * Y) + INT [2.6 * (M+1)] + D}
DotW = 7 * FRAC {--------------------------------------}
{ 7 }

BUT January and February MUST be considered to be the 13th and 14th months
of the PREVIOUS year! Thus 2/10/88 becomes 14/10/87 for this purpose.
This handles the otherwise messy business of leap year by placing leap day
at the end of the "year". The expression INT [2.6 * (M+1)] advances the
days correctly from the 3rd through the 14th months.

....[calculation examples snipped]....

The above procedures handle dates from 3/1/1900 through 2/29/2000.
For other centuries: 16xx add 6 <<<<<<< TO WHAT?
17xx add 4 <<<<<<< TO WHAT?
18xx add 2 <<<<<<< TO WHAT?

Since the calendar repeats every 400 years, this provides a complete
specification.
---------- cut here ---------- cut here ---------- cut here ----------

Well, I'm pretty good at translating simple equations to many langauges,
but the above equation first FAILED because whatever machine Mr. Benford
used must have calculated FRACtions to only 4-5 digits and then rounded up;
the machine (PC) and languages (MS FORTRAN 5.x and NortonsDOS scripts) I
used calculated to many more, so 7 * more digits did NOT quite reach the
proper integer (for example, what should have been just bigger than 1.x
was calculated to be 0.9999997, which, as an integer, was zero).

Also, his little comment "add 6/4/2" didn't say to what the 6/4/2 should
be added, but I guessed it should be added to the "day" and that seemed
to work.

But his algorithm failed for dates before September, 1752 (was that the
date the Gregorian calendar was adopted?), but I fumbled around and got
past that problem (I think).

Then I did some more spot-checking and found another date (a leap-year-2000
date) that didn't work. On and on and on and .........

Can someone cite a day-of-the-week algorithm THAT WORKS?

--Myron A. Calhoun
--
Five boxes preserve our freedoms: soap, ballot, witness, jury, and cartridge
PhD EE (retired). "Barbershop" tenor. CDL(PTX). W0PBV. (785) 539-4448
NRA Life Member and Certified Instructor (Home Firearm Safety, Rifle, Pistol)

John Harper

unread,
Aug 19, 2003, 5:33:49 PM8/19/03
to
In article <bhu1rp$f...@unix1.cc.ksu.edu>, mcalhoun <mcal...@ksu.edu> wrote:
>
>But his algorithm failed for dates before September, 1752 (was that the
>date the Gregorian calendar was adopted?), but I fumbled around and got
>past that problem (I think).

Sept 1752 was when the Gregorian calendar was adopted in some places
(UK and its colonies including the American 13). But even in what is now
USA different places adopted it at different times: Alaska when USA
bought it from Russia; the states which were French or Spanish colonies
in 1752 presumably adopted it in Oct 1582, or when they became colonies
if that was later; and Hawaii when? Similar complications exist
elsewhere because the 1582 change was decreed by the Pope and it took
centuries for governments of mainly Protestant or Orthodox or non-
Christian countries to be convinced that the Catholic astronomers had
done a good job. See

Dershowitz, M. and Reingold, E.M. Calendrical Calculations, Cambridge
University Press, 1997

Duncan, D.E. The Calendar, Fourth Estate, London, 1998 reprinted 1999

Dutka, J. On the Gregorian revision of the Julian calendar,
Mathematical Intelligencer, 10(1) 56--64, 1988

Gregory XIII, Pope. Inter Gravissimas, 1581/2. See
http://personal.ecu.edu/MCCARTYR/intGrvEng.html

John Harper, School of Mathematical and Computing Sciences,
Victoria University, PO Box 600, Wellington, New Zealand
e-mail john....@vuw.ac.nz phone (+64)(4)463 5341 fax (+64)(4)463 5045

Dave Seaman

unread,
Aug 19, 2003, 7:56:30 PM8/19/03
to

This works for all dates according to the Gregorian calendar (the
one adopted on 1752 in English-speaking countries):


int dayofweek(int day, int month, int year)
/* Mon. = 0, Sun. = 6 */
{
if (month < 3) {
month += 12;
year--;
}
return ((13*month+3)/5 + day + year + year/4 - year/100 +
year/400) % 7;
}

Notice that this function contains no floating-point constants.
A correct algorithm should use integer arithmetic exclusively in
order to avoid roundoff error.

Sorry for posting C in a Fortran group, but the translation should be
pretty obvious. The C code has the advantage of having been tested.


--
Dave Seaman
Judge Yohn's mistakes revealed in Mumia Abu-Jamal ruling.
<http://www.commoncouragepress.com/index.cfm?action=book&bookid=228>

analyst41

unread,
Aug 20, 2003, 7:42:05 AM8/20/03
to
Dave Seaman <dse...@no.such.host> wrote in message news:<bhudfe$p8s$1...@mozo.cc.purdue.edu>...

Looks very elegant.

Is there something equally pretty to calculate the difference in days
between mm1 dd1 yy1 and mm2 dd2 yy2 ?

Thanks.

Herman D. Knoble

unread,
Aug 20, 2003, 8:19:41 AM8/20/03
to
Myron: There is a working day of the week algorithm in Fortran 90 at:
http://ftp.cac.psu.edu/pub/ger/fortran/hdk/datesub.f90
and for Fortran 77 at:
http://ftp.cac.psu.edu/pub/ger/fortran/hdk/datesub.for

This algorithm does not suffer the problem you mention.

Skip Knoble, Penn State

n 19 Aug 2003 15:38:17 -0500, mcal...@ksu.edu (mcalhoun) wrote:

-|I've seen several algorithms which calculate the day-of-the-week (usually
-|0=Sunday, 1=Monday, ... 6=Saturday), but I've NEVER found one that works
-|for all cases (I test them against the UNIX "cal"). For example, the
-|Summer, 1999, Tau Beta Pi magazine had an article by Howard L. Benford
-|which said (paraphrasing):
-|
-|---------- cut here ---------- cut here ---------- cut here ----------
-|Given a date in the usual "M/D/Y" form, the day of the week (DotW) can
-|be calculated as an integer from 0 through 6 representing Sunday through
-|Saturday, respectively:
-|
-| {INT (1.25 * Y) + INT [2.6 * (M+1)] + D}
-| DotW = 7 * FRAC {--------------------------------------}
-| { 7 }
-|
-|BUT January and February MUST be considered to be the 13th and 14th months
-|of the PREVIOUS year! Thus 2/10/88 becomes 14/10/87 for this purpose.
-|This handles the otherwise messy business of leap year by placing leap day
-|at the end of the "year". The expression INT [2.6 * (M+1)] advances the
-|days correctly from the 3rd through the 14th months.
-|
-|....[calculation examples snipped]....
-|
-|The above procedures handle dates from 3/1/1900 through 2/29/2000.
-|For other centuries: 16xx add 6 <<<<<<< TO WHAT?
-| 17xx add 4 <<<<<<< TO WHAT?
-| 18xx add 2 <<<<<<< TO WHAT?
-|
-|Since the calendar repeats every 400 years, this provides a complete
-|specification.
-|---------- cut here ---------- cut here ---------- cut here ----------
-|
-|Well, I'm pretty good at translating simple equations to many langauges,
-|but the above equation first FAILED because whatever machine Mr. Benford
-|used must have calculated FRACtions to only 4-5 digits and then rounded up;
-|the machine (PC) and languages (MS FORTRAN 5.x and NortonsDOS scripts) I
-|used calculated to many more, so 7 * more digits did NOT quite reach the
-|proper integer (for example, what should have been just bigger than 1.x
-|was calculated to be 0.9999997, which, as an integer, was zero).
-|
-|Also, his little comment "add 6/4/2" didn't say to what the 6/4/2 should
-|be added, but I guessed it should be added to the "day" and that seemed
-|to work.
-|
-|But his algorithm failed for dates before September, 1752 (was that the
-|date the Gregorian calendar was adopted?), but I fumbled around and got
-|past that problem (I think).
-|
-|Then I did some more spot-checking and found another date (a leap-year-2000
-|date) that didn't work. On and on and on and .........
-|
-|Can someone cite a day-of-the-week algorithm THAT WORKS?
-|
-|--Myron A. Calhoun


Herman D. (Skip) Knoble, Research Associate
(a computing professional for 38 years)
Mailto:h...@psu.edu
Web: http://www.personal.psu.edu/hdk
Penn State Information Technology Services
Academic Services and Emerging Technologies
Graduate Education and Research Services
Penn State University
214C Computer Building
University Park, PA 16802-21013
Phone:+1 814 865-0818 Fax:+1 814 863-7049

Herman D. Knoble

unread,
Aug 20, 2003, 8:23:13 AM8/20/03
to

Dave: Yes, The computation of the difference between two dates is also in
the Fortran Date routines that I posted earlier on this thread.

Skip Knoble, Penn State

On 20 Aug 2003 04:42:05 -0700, anal...@hotmail.com (analyst41) wrote:

-|Dave Seaman <dse...@no.such.host> wrote in message
news:<bhudfe$p8s$1...@mozo.cc.purdue.edu>...


-|> On 19 Aug 2003 15:38:17 -0500, mcalhoun wrote:
-|> > I've seen several algorithms which calculate the day-of-the-week (usually
-|> > 0=Sunday, 1=Monday, ... 6=Saturday), but I've NEVER found one that works
-|> > for all cases (I test them against the UNIX "cal"). For example, the
-|> > Summer, 1999, Tau Beta Pi magazine had an article by Howard L. Benford
-|> > which said (paraphrasing):
-|>
-|> > ---------- cut here ---------- cut here ---------- cut here ----------
-|> > Given a date in the usual "M/D/Y" form, the day of the week (DotW) can
-|> > be calculated as an integer from 0 through 6 representing Sunday through
-|> > Saturday, respectively:
-|>

-|> > {INT (1.25 * Y) + INT [2.6 * (M+1)] + D}
-|> > DotW = 7 * FRAC {--------------------------------------}
-|> > { 7 }
-|>
-|> > BUT January and February MUST be considered to be the 13th and 14th months
-|> > of the PREVIOUS year! Thus 2/10/88 becomes 14/10/87 for this purpose.
-|> > This handles the otherwise messy business of leap year by placing leap day
-|> > at the end of the "year". The expression INT [2.6 * (M+1)] advances the
-|> > days correctly from the 3rd through the 14th months.
-|>
-|> > ....[calculation examples snipped]....
-|>
-|> > The above procedures handle dates from 3/1/1900 through 2/29/2000.
-|> > For other centuries: 16xx add 6 <<<<<<< TO WHAT?
-|> > 17xx add 4 <<<<<<< TO WHAT?
-|> > 18xx add 2 <<<<<<< TO WHAT?
-|>
-|> > Since the calendar repeats every 400 years, this provides a complete
-|> > specification.
-|> > ---------- cut here ---------- cut here ---------- cut here ----------
-|>
-|> This works for all dates according to the Gregorian calendar (the
-|> one adopted on 1752 in English-speaking countries):
-|>
-|>
-|> int dayofweek(int day, int month, int year)
-|> /* Mon. = 0, Sun. = 6 */
-|> {
-|> if (month < 3) {
-|> month += 12;
-|> year--;
-|> }
-|> return ((13*month+3)/5 + day + year + year/4 - year/100 +
-|> year/400) % 7;
-|> }
-|>
-|> Notice that this function contains no floating-point constants.
-|> A correct algorithm should use integer arithmetic exclusively in
-|> order to avoid roundoff error.
-|>
-|> Sorry for posting C in a Fortran group, but the translation should be
-|> pretty obvious. The C code has the advantage of having been tested.
-|
-|Looks very elegant.
-|
-|Is there something equally pretty to calculate the difference in days
-|between mm1 dd1 yy1 and mm2 dd2 yy2 ?
-|
-|Thanks.

Gordon Sande

unread,
Aug 20, 2003, 8:34:27 AM8/20/03
to

>> > Given a date in the usual "M/D/Y" form, the day of the week (DotW) can
>> > be calculated as an integer from 0 through 6 representing Sunday through
>> > Saturday, respectively:


W. Kahan (U.C.Berkeley) has a file called DAYDATE which goes through many
of the issues.


Dr John Stockton

unread,
Aug 20, 2003, 8:10:20 AM8/20/03
to
JRS: In article <bhu1rp$f...@unix1.cc.ksu.edu>, seen in
news:comp.os.msdos.misc, mcalhoun <mcal...@ksu.edu> posted at Tue, 19
Aug 2003 15:38:17 :-

>
>Can someone cite a day-of-the-week algorithm THAT WORKS?

<URL:http://www.merlyn.demon.co.uk/zeller-c.htm>
<URL:http://www.merlyn.demon.co.uk/programs/dateprox.pas>

Dateprox has a general first-principles method, not involving floating-
point.

Actually, all that one needs to do is to take the Chronological Julian
Date Number, and find the remainder after division by 7. Then by adding
one to the remainder you get the ISO-8601 day-of-week number. You may
remember that BC 4713 Jan 1st was a Monday.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.

Michel OLAGNON

unread,
Aug 21, 2003, 3:25:13 AM8/21/03
to

In article <kOBVPCEsU2Q$Ew...@merlyn.demon.co.uk>, Dr John Stockton <sp...@merlyn.demon.co.uk> writes:
> You may remember that BC 4713 Jan 1st was a Monday.
>

My memory is no longer as good as it was then... :-),
but I would advise to rather check the implementation
with the current day. BC 4713 Jan 1st is confusing when one wonders
about length 0 of year 0, or about the gregorian calendar change.

Tony T. Warnock

unread,
Aug 21, 2003, 9:24:09 AM8/21/03
to
FUNCTION juldate (year,month,day)
c
c Converts DAY/MONTH/YEAR to a Julian date transformed to 2000
c
IMPLICIT NONE
c
INTEGER juldate, day, month, year
c
juldate=367*year-7*(year+(month+9)/12)/4-3*((year+(month-9)/7)/100

1 +1)/4+275*month/9+day-730516
END


The constant 730516 can be adjusted to match any date desired as the
starting point or to change Gregorian dates to Julian.

analyst41

unread,
Aug 22, 2003, 6:55:30 AM8/22/03
to
"Tony T. Warnock" <u09...@cic-mail.lanl.gov> wrote in message news:<3F44C7F9...@cic-mail.lanl.gov>...

Thank you. Once you have this function, DOW(mm,dd,yy) becomes trivial
- pick a fixed date with known DOW = 0 and take the MOD 7 difference
between the Julian dates of the fixed date and the target date.

Joe Geluso

unread,
Aug 22, 2003, 2:34:06 PM8/22/03
to
On Thu, 21 Aug 2003 07:24:09 -0600, "Tony T. Warnock"
<u09...@cic-mail.lanl.gov> wrote:

>FUNCTION juldate (year,month,day)
>c
>c Converts DAY/MONTH/YEAR to a Julian date transformed to 2000
>c
> IMPLICIT NONE
>c
> INTEGER juldate, day, month, year
>c
> juldate=367*year-7*(year+(month+9)/12)/4-3*((year+(month-9)/7)/100
>
> 1 +1)/4+275*month/9+day-730516
> END


Reading posts in comp.os.msdos.misc

Is my translation to BASIC faulty or does this formula have trouble
with dates before September 1, 1900?

yyyy-mm-dd value reported the program below

1900-08-31 -36281
1900-09-01 -36281

The BASIC rendering below is broken into many statements to clarify
where integer division is being emulated in a language that doesn't
support integer variable types.


======= Attempted rendering in True BASIC =====
DO while more data
READ year, month, day

LET a1= int((month+9)/12)
LET a2= 7*(year+ a1)

LET b1= int((month-9)/7)
LET b2= int((year+b1)/100)
LET b3= 3*(b2 +1)

LET c1= 275*month

LET juldate= 367 * year
LET juldate = juldate - int(a2/4)
LET juldate = juldate - int(b3/4)
LET juldate = juldate + int(c1/9) + day - 730516

PRINT year;month;day,juldate
LOOP

DATA 1900, 8, 31
DATA 1900, 9, 1

END
=============

What values are reported by posted function for August 31 and
September 1, 1900 when it is run in FORTRAN?


Thanks.

Joe Geluso

Tony T. Warnock

unread,
Aug 22, 2003, 3:15:39 PM8/22/03
to
Check the size of your integers. The appearance of 32xxx numbers is
often a sign of 16 bit integer arithmetic. The formula came from a
48-bit Fortran from the 1960s. It does work with 32 bit integers.

James Giles

unread,
Aug 22, 2003, 3:30:10 PM8/22/03
to
Joe Geluso wrote:
...
> LET b1= int((month-9)/7)

My suspicion is that your Basic implementation defines INT as Fortran
defines FLOOR. If you write out b1 when you month is august, do you
get zero or minus one? Fortran would give zero.

--
J. Giles


Joe Geluso

unread,
Aug 22, 2003, 5:01:19 PM8/22/03
to
On Fri, 22 Aug 2003 19:30:10 GMT, "James Giles"
<james...@worldnet.att.net> wrote:

>Joe Geluso wrote:
>...
>> LET b1= int((month-9)/7)
>
>My suspicion is that your Basic implementation defines INT as Fortran

>defines FLOOR. If you write out b1 when your month is august, do you


>get zero or minus one? Fortran would give zero.

Bingo!

The IP function in True BASIC (and apparently the FIX function in
Qbasic) is apparently comparable to the INT function in FORTRAN.

int(-1/7) = -1
ip(-1/7) = 0

The revised translation of posted formula to BASIC now also checks out
for January 1, 1900 -- unlike an early version of a certain
spreadsheet, which failed to recognize that 1900 was not a leap year.


Thanks.

Joe Geluso

John Harper

unread,
Aug 24, 2003, 6:17:06 PM8/24/03
to
In article <jfockv05tvlu8l9t4...@4ax.com>,

Joe Geluso <jg.ne...@gbronline.com> wrote:
>On Thu, 21 Aug 2003 07:24:09 -0600, "Tony T. Warnock"
><u09...@cic-mail.lanl.gov> wrote:
(snip)
>> juldate=367*year-7*(year+(month+9)/12)/4-3*((year+(month-9)/7)/100
>> 1 +1)/4+275*month/9+day-730516
(snip)

>Is my translation to BASIC faulty or does this formula have trouble
>with dates before September 1, 1900?
>
>1900-08-31 -36281
>1900-09-01 -36281
(snip)

>What values are reported by posted function for August 31 and
>September 1, 1900 when it is run in FORTRAN?

With Compaq Fortran Compiler V5.5-1877-48BBF I got

1900-08-31 -36282
1900-09-01 -36281

so the Basic is bad. However the Fortran is also dangerous: it did not
object either to an impossible date like 1900-02-32 or 2002-15-15, nor
to a date before the Julian-Gregorian change like 1582-09-09.

analyst41

unread,
Aug 25, 2003, 9:41:19 AM8/25/03
to
har...@mcs.vuw.ac.nz (John Harper) wrote in message news:<10617634...@bats.mcs.vuw.ac.nz>...

> In article <jfockv05tvlu8l9t4...@4ax.com>,
> Joe Geluso <jg.ne...@gbronline.com> wrote:
> >On Thu, 21 Aug 2003 07:24:09 -0600, "Tony T. Warnock"
> ><u09...@cic-mail.lanl.gov> wrote:
> (snip)
> >> juldate=367*year-7*(year+(month+9)/12)/4-3*((year+(month-9)/7)/100
> >> 1 +1)/4+275*month/9+day-730516
> (snip)
> >Is my translation to BASIC faulty or does this formula have trouble
> >with dates before September 1, 1900?
> >
> >1900-08-31 -36281
> >1900-09-01 -36281
> (snip)
> >What values are reported by posted function for August 31 and
> >September 1, 1900 when it is run in FORTRAN?
>
> With Compaq Fortran Compiler V5.5-1877-48BBF I got
>
> 1900-08-31 -36282
> 1900-09-01 -36281
>
> so the Basic is bad. However the Fortran is also dangerous: it did not
> object either to an impossible date like 1900-02-32 or 2002-15-15, nor
> to a date before the Julian-Gregorian change like 1582-09-09.
>

I think that fairly elementary filters in the calling routine ought to
be able to take care of this - one could even filter for 1 <= month
<=12 etc. in this routine itself.

The main quetion is does it work for correct inputs for the
appropriate range of dates and I believe that it does and one ought to
focus on the amazing fact that one does not need to carry an array
containing 31,28,31....etc. to accomplish this and one does not need
to explicitly check for leap year.

I believe that this one line fucntion easily qualifies as a FORTRAN
gem.

Dr John Stockton

unread,
Aug 25, 2003, 8:55:24 AM8/25/03
to
JRS: In article <10617634...@bats.mcs.vuw.ac.nz>, seen in
news:comp.os.msdos.misc, John Harper <har...@mcs.vuw.ac.nz> posted at
Sun, 24 Aug 2003 22:17:06 :-

> However the Fortran is also dangerous: it did not

>object ...


>to a date before the Julian-Gregorian change like 1582-09-09.

It should not do so; that is a perfectly valid date on the proleptic
Gregorian Calendar.

Date Validation and Date-to-Count are different concepts, and should not
be conflated.

Date Validation needs to be provided with the Julian/Gregorian change
date as a parameter, if the change is to be taken into consideration.


By the way, the British Calendar Act of 1751 specifically applies "in
Europe, Asia, Africa and America" - so those in Australasia and Oceania
are excluded from its obligations.

Annie

unread,
Aug 26, 2003, 4:48:11 AM8/26/03
to
**** Post for FREE via your newsreader at post.usenet.com ****

On 2003-08-25 re...@merlyn.demon.co.uk said:

> By the way, the British Calendar Act of 1751 specifically applies
> "in Europe, Asia, Africa and America" - so those in Australasia and
> Oceania are excluded from its obligations.

_____
You sure as hell seem to place ((( `\
a lot of trust and confidence _ _`\ )
in Guvvermint mandates, Doctor (^ ) )
John...even ones that are over ~-( )
250 years old. _'((,,,)))
,-' \_/ `\
Well, I don't. I'm in America, ( , |
and I can guarantee you that `-.-'`-.-'/|_|
the British Calendar Act \ / | |
imposes absolutely NO obligations =()=: / ,' aa
on ME. I choose to ignore it
completely.

Stuff THAT into your stodgy old
pipe, and blow. Hehehe!

Love,
Annie

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*** Usenet.com - The #1 Usenet Newsgroup Service on The Planet! ***
http://www.usenet.com
Unlimited Download - 19 Seperate Servers - 90,000 groups - Uncensored
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Charles Dye

unread,
Aug 26, 2003, 8:47:14 AM8/26/03
to
On 26 Aug 2003 03:48:11 -0500, "Annie" <an...@oal.cm> wrote:

> Well, I don't. I'm in America,

> and I can guarantee you that

> the British Calendar Act
> imposes absolutely NO obligations


> on ME. I choose to ignore it
> completely.

So this is the thirteenth for you, then?

--
Charles Dye ras...@highfiber.com


Dr John Stockton

unread,
Aug 26, 2003, 2:48:03 PM8/26/03
to
JRS: In article <0almkvk9fti2keaf4...@4ax.com>, seen in
news:comp.os.msdos.misc, Charles Dye <ras...@highfiber.com> posted at
Tue, 26 Aug 2003 06:47:14 :-

>On 26 Aug 2003 03:48:11 -0500, "Annie" <an...@oal.cm> wrote:
>
>> Well, I don't. I'm in America,
>> and I can guarantee you that
>> the British Calendar Act
>> imposes absolutely NO obligations
>> on ME. I choose to ignore it
>> completely.
>
>So this is the thirteenth for you, then?

I think that you are assuming more intelligence and knowledge than it is
reasonable to suppose exists in the target.

I have no doubt that the Act was implemented in the American Colonies on
the proper date (but probably with complaints); and AIUI the USA
inherited all previous arrangements except for those that it
specifically changed. Which, in this case, it did not.

Most of the subsequent increase in the size of the USA was by absorption
of already-Gregorian (or, at least, non-Julian) territories. I imagine
that the Sandwich Islands would not at that time have been Gregorian.
But Alaska was Julian before the purchase. Is it known whether
legislation relating to date was involved? What does a genuine Alaskan
Calendar covering October 1867 look like, in English?

Charles Dye

unread,
Aug 27, 2003, 8:45:10 AM8/27/03
to
On Tue, 26 Aug 2003 19:48:03 +0100, Dr John Stockton
<sp...@merlyn.demon.co.uk> wrote:

>Most of the subsequent increase in the size of the USA was by absorption
>of already-Gregorian (or, at least, non-Julian) territories. I imagine
>that the Sandwich Islands would not at that time have been Gregorian.
>But Alaska was Julian before the purchase. Is it known whether
>legislation relating to date was involved? What does a genuine Alaskan
>Calendar covering October 1867 look like, in English?

Interesting question, but I doubt there ever was any formal date and
mechanism. Certainly Alaska didn't have any government, railroads
or telegraphs until years after the Seward purchase. _Territorial_
status wasn't conferred until 1912.

In practise, I'd be willing to bet that English- and French-speaking
frontiersmen used New Style all along, and Russian speakers probably
continued to use Julian until it became too inconvenient. For that
matter, Orthodox churches still use it today.

--
Charles Dye ras...@highfiber.com


Roby

unread,
Aug 28, 2003, 3:56:19 PM8/28/03
to
Dave Seaman wrote:

> On 19 Aug 2003 15:38:17 -0500, mcalhoun wrote:

(snip)


>
> This works for all dates according to the Gregorian calendar (the
> one adopted on 1752 in English-speaking countries):
>
>
> int dayofweek(int day, int month, int year)
> /* Mon. = 0, Sun. = 6 */
> {
> if (month < 3) {
> month += 12;
> year--;
> }
> return ((13*month+3)/5 + day + year + year/4 - year/100 +
> year/400) % 7;
> }
>
> Notice that this function contains no floating-point constants.
> A correct algorithm should use integer arithmetic exclusively in
> order to avoid roundoff error.
>
> Sorry for posting C in a Fortran group, but the translation should be
> pretty obvious. The C code has the advantage of having been tested.

I compiled dayofweek() and found that it returned the previous day; i.e.,
when day=28, month=8, year=2003 it returns 3 (=Wednesday) rather than 4.

I think the last line oughta be

return ((13*month+3)/5 + day + year + year/4 - year/100 +

year/400 + 1) % 7;

Roby

Dave Seaman

unread,
Aug 28, 2003, 4:11:42 PM8/28/03
to
On Thu, 28 Aug 2003 19:56:19 GMT, Roby wrote:
> Dave Seaman wrote:

>> On 19 Aug 2003 15:38:17 -0500, mcalhoun wrote:
> (snip)

>> This works for all dates according to the Gregorian calendar (the
>> one adopted on 1752 in English-speaking countries):


>> int dayofweek(int day, int month, int year)
>> /* Mon. = 0, Sun. = 6 */
>> {
>> if (month < 3) {
>> month += 12;
>> year--;
>> }
>> return ((13*month+3)/5 + day + year + year/4 - year/100 +
>> year/400) % 7;
>> }

>> Notice that this function contains no floating-point constants.
>> A correct algorithm should use integer arithmetic exclusively in
>> order to avoid roundoff error.

>> Sorry for posting C in a Fortran group, but the translation should be
>> pretty obvious. The C code has the advantage of having been tested.

> I compiled dayofweek() and found that it returned the previous day; i.e.,
> when day=28, month=8, year=2003 it returns 3 (=Wednesday) rather than 4.

You didn't read the comment in the code. The correct result is 3, since
the comment /* Mon. = 0, Sun. = 6 */ implies that 3=Thursday, not
Wednesday.

> I think the last line oughta be

> return ((13*month+3)/5 + day + year + year/4 - year/100 +
> year/400 + 1) % 7;

If you prefer, but don't forget to change the comment when you change the
code.

Dr John Stockton

unread,
Aug 31, 2003, 10:09:28 AM8/31/03
to
JRS: In article <bilnlu$eld$1...@mozo.cc.purdue.edu>, seen in
news:comp.os.msdos.misc, Dave Seaman <dse...@no.such.host> posted at
Thu, 28 Aug 2003 20:11:42 :-

>
>> I compiled dayofweek() and found that it returned the previous day; i.e.,
>> when day=28, month=8, year=2003 it returns 3 (=Wednesday) rather than 4.
>
>You didn't read the comment in the code. The correct result is 3, since
>the comment /* Mon. = 0, Sun. = 6 */ implies that 3=Thursday, not
>Wednesday.

August 28, 2003, was a Thursday.

The correct result is therefore 4, because ISO 8061 numbers the days of
the week from Mon=1 to Sun=7. This agrees with the Book of Genesis and
with Archbishop Ussher of Armagh; I understand that ISO 8601 is also
adopted as a US Federal Standard, for whatever that's worth.

In practice, all that one can reasonably assume of Day-of-Week code is
that it gives either 0..6 or 1..7, cyclically; and that the least number
is probably Sunday or Monday, except for those of some rather well-known
faiths.

Dave Seaman

unread,
Aug 31, 2003, 2:30:52 PM8/31/03
to
On Sun, 31 Aug 2003 15:09:28 +0100, Dr John Stockton wrote:
> JRS: In article <bilnlu$eld$1...@mozo.cc.purdue.edu>, seen in
> news:comp.os.msdos.misc, Dave Seaman <dse...@no.such.host> posted at
> Thu, 28 Aug 2003 20:11:42 :-
>>
>>> I compiled dayofweek() and found that it returned the previous day; i.e.,
>>> when day=28, month=8, year=2003 it returns 3 (=Wednesday) rather than 4.
>>
>>You didn't read the comment in the code. The correct result is 3, since
>>the comment /* Mon. = 0, Sun. = 6 */ implies that 3=Thursday, not
>>Wednesday.

> August 28, 2003, was a Thursday.

I thought that much was already quite clear.

> The correct result is therefore 4, because ISO 8061 numbers the days of
> the week from Mon=1 to Sun=7.

The correct result is 3, because I number the days of the week from Mon=0
to Sun=6, and I said so in the function I posted. For those who are able
to read, the algorithm is entirely correct.

>This agrees with the Book of Genesis and
> with Archbishop Ussher of Armagh; I understand that ISO 8601 is also
> adopted as a US Federal Standard, for whatever that's worth.

I am an atheist. I don't base my algorithms on Genesis or any other
ancient writings. Adding a constant would merely lengthen the code for
no discernable purpose except reordering the strings in a table of the
names of the days.

> In practice, all that one can reasonably assume of Day-of-Week code is
> that it gives either 0..6 or 1..7, cyclically; and that the least number
> is probably Sunday or Monday, except for those of some rather well-known
> faiths.

And yet you chose to be unreasonable.

Brooks Moses

unread,
Aug 31, 2003, 2:54:00 PM8/31/03
to
Dr John Stockton wrote:
> JRS: In article <bilnlu$eld$1...@mozo.cc.purdue.edu>, seen in
> news:comp.os.msdos.misc, Dave Seaman <dse...@no.such.host> posted at
> Thu, 28 Aug 2003 20:11:42 :-
> >You didn't read the comment in the code. The correct result is 3, since
> >the comment /* Mon. = 0, Sun. = 6 */ implies that 3=Thursday, not
> >Wednesday.
>
> August 28, 2003, was a Thursday.
>
> The correct result is therefore 4, because ISO 8061 numbers the days of
> the week from Mon=1 to Sun=7. This agrees with the Book of Genesis and
> with Archbishop Ussher of Armagh; I understand that ISO 8601 is also
> adopted as a US Federal Standard, for whatever that's worth.

I feel somewhat bad being theologically picky here, but it doesn't
really agree with the Book of Genesis at all; the Sabbath is generally
held to be Saturday. Consider how the days in Easter week are observed
-- Sunday is the (usual) Christian day of worship because it's the day
associated with the Resurrection, which was the day after the Sabbath.

- Brooks

Toon Moene

unread,
Aug 31, 2003, 3:17:03 PM8/31/03
to
Dave Seaman wrote:

> I am an atheist.

Then why base your computations on Monday being day zero ? Or why start
with zero anyway ?

[ I suppose you don't mind the last calendar reform was initiated by a
pope ? ]

Fortran users (of all convictions) would start with "one" anyway.

--
Toon Moene - mailto:to...@moene.indiv.nluug.nl - phoneto: +31 346 214290
Saturnushof 14, 3738 XG Maartensdijk, The Netherlands
Maintainer, GNU Fortran 77: http://gcc.gnu.org/onlinedocs/g77_news.html
GNU Fortran 95: http://gcc-g95.sourceforge.net/ (under construction)

Dave Seaman

unread,
Aug 31, 2003, 3:52:28 PM8/31/03
to
On Sun, 31 Aug 2003 21:17:03 +0200, Toon Moene wrote:
> Dave Seaman wrote:

>> I am an atheist.

> Then why base your computations on Monday being day zero ? Or why start
> with zero anyway ?

I didn't choose Monday. The algorithm chose Monday for me, because that
convention leads to the simplest code. And I start with 0 because that's
how "mod" is defined.

> [ I suppose you don't mind the last calendar reform was initiated by a
> pope ? ]

No.

> Fortran users (of all convictions) would start with "one" anyway.

That's not how "mod" works, and Fortran does have 0-based arrays.

Dr John Stockton

unread,
Sep 1, 2003, 7:31:01 AM9/1/03
to
JRS: In article <bitess$qaq$2...@mozo.cc.purdue.edu>, seen in

news:comp.os.msdos.misc, Dave Seaman <dse...@no.such.host> posted at
Sun, 31 Aug 2003 18:30:52 :-

>On Sun, 31 Aug 2003 15:09:28 +0100, Dr John Stockton wrote:
>> JRS: In article <bilnlu$eld$1...@mozo.cc.purdue.edu>, seen in
>> news:comp.os.msdos.misc, Dave Seaman <dse...@no.such.host> posted at
>> Thu, 28 Aug 2003 20:11:42 :-
>>>
>>>> I compiled dayofweek() and found that it returned the previous day; i.e.,
>>>> when day=28, month=8, year=2003 it returns 3 (=Wednesday) rather than 4.
>>>
>>>You didn't read the comment in the code. The correct result is 3, since
>>>the comment /* Mon. = 0, Sun. = 6 */ implies that 3=Thursday, not
>>>Wednesday.
>
>> August 28, 2003, was a Thursday.
>
>I thought that much was already quite clear.

It was stated; it was well-known. I was establishing it as reliable,
in a manner which might help those reading this later; and as a
preliminary to the following "therefore".

>> The correct result is therefore 4, because ISO 8061 numbers the days of
>> the week from Mon=1 to Sun=7.
>
>The correct result is 3, because I number the days of the week from Mon=0
>to Sun=6, and I said so in the function I posted. For those who are able
>to read, the algorithm is entirely correct.

The algorithm may be consistent with its own documentation, but that
does not imply that the number that it gives is the correct number for
the day of the week. It would be another matter if the algorithm,
although using a non-standard number internally, returned a string.


>>This agrees with the Book of Genesis and
>> with Archbishop Ussher of Armagh; I understand that ISO 8601 is also
>> adopted as a US Federal Standard, for whatever that's worth.
>
>I am an atheist. I don't base my algorithms on Genesis or any other
>ancient writings.

Your algorithms are so based, or need to be, since you are probably
living in a country - you do not state which one - which uses the
Gregorian Calendar. This, for us, is authorised by the Calendar Act
(inherited by the US, and not overturned), which is based on the need to
agree with the Papal Bull of 1582, which has a firm religious - indeed
Christian - basis. Chronologically, for civil purposes, the world is
almost entirely Gregorian, and this is one of the rare cases where the
USA is in full compliance with international standards.

AIUI, the USA is already formally using the international standard for
the numbering of the days of the week. Eventually, it is probable that
the majority - one cannot reasonably expect much more - of the people of
that country will comply with their own Federal standard.

BTW : as regards the Act and the Bull - they give full details as
regards Leap Years, but cite other documents for Easter. I'd like a URL
for these others.

Dr John Stockton

unread,
Sep 1, 2003, 8:04:22 AM9/1/03
to
JRS: In article <3F524448...@cits1.stanford.edu>, seen in
news:comp.os.msdos.misc, Brooks Moses <bmoses...@cits1.stanford.edu>
posted at Sun, 31 Aug 2003 11:54:00 :-

It agrees on the basis that, in Genesis, the day of rest is Number 7;
and, in ISO 8601, the day of most general rest is Sunday. However the
week is numbered, if it has a Day 7 that must be followed by Day 1,
starting the next week.

One needs to be theologically, arithmetically, and historically picky.

Ussher may have been cosmologically unsound; but he evidently was a
careful worker who knew his business. We can no longer accept his
arguments that the Creation can be historically dated as the actual
event of Genesis 1:1 by counting Biblical lifetimes back from a known
date; but there seems no doubt that he understood the seven-day week and
know that, on that basis, Julian BC 4004 Oct 23 was a Sunday, exactly
7*N days before the says of his (presumed) Sunday sermons. That, I
believe, is the date Ussher gives.

Ussher wrote : "... from the evening ushering in the first day of the
World, to that midnight which began the first day of the Christian era,
there was 4003 years, seventy days, and six temporarie hours".

A.D. 0001-01-01 0h minus 4003y 70d 6h is B.C. 4004-10-22 18h,
<i>i.e.</i> 6 p.m. of Saturday 22nd October, B.C. 4004. That makes the
first full day Sunday 23rd (Genesis, 1,5; the seventh day, of rest, is
the Jewish Sabbath). Garden of Eden Time, presumably.

Remember that it was the custom for religious purposes to start the date
at sunset, or 6pm, of what we would call the previous day, which is
consistent with "And the evening and the morning were the first day" or
similar, in Gen.1:5.


ISTM that the Jewish Sabbath is exactly consistent with Ussher's
interpretation of the beginning of the Book of Genesis; their
interpretation of the chronology presumably differs, since they put the
Creation in BC 3761. And that the Christian day of rest is shifted for
Paschal reasons; if the day of rest is called the Sabbath, that implies
a discontinuity.

The Jewish Creation was, it seems, on a Monday, numbered Day 2, which
puts their Sabbath consistently at Day 7. But they seem to have started
their Calendar in a peculiarly confusing manner.



--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©

Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links;
some Astro stuff via astro.htm, gravity0.htm; quotes.htm; pascal.htm; &c, &c.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.

Dave Seaman

unread,
Sep 2, 2003, 12:42:33 AM9/2/03
to
On Mon, 1 Sep 2003 12:31:01 +0100, Dr John Stockton wrote:
> JRS: In article <bitess$qaq$2...@mozo.cc.purdue.edu>, seen in
> news:comp.os.msdos.misc, Dave Seaman <dse...@no.such.host> posted at
> Sun, 31 Aug 2003 18:30:52 :-
>>On Sun, 31 Aug 2003 15:09:28 +0100, Dr John Stockton wrote:
>>> JRS: In article <bilnlu$eld$1...@mozo.cc.purdue.edu>, seen in
>>> news:comp.os.msdos.misc, Dave Seaman <dse...@no.such.host> posted at
>>> Thu, 28 Aug 2003 20:11:42 :-

>>>>> I compiled dayofweek() and found that it returned the previous day; i.e.,
>>>>> when day=28, month=8, year=2003 it returns 3 (=Wednesday) rather than 4.

>>>>You didn't read the comment in the code. The correct result is 3, since
>>>>the comment /* Mon. = 0, Sun. = 6 */ implies that 3=Thursday, not
>>>>Wednesday.

>>> The correct result is therefore 4, because ISO 8061 numbers the days of


>>> the week from Mon=1 to Sun=7.

>>The correct result is 3, because I number the days of the week from Mon=0
>>to Sun=6, and I said so in the function I posted. For those who are able
>>to read, the algorithm is entirely correct.

> The algorithm may be consistent with its own documentation, but that
> does not imply that the number that it gives is the correct number for
> the day of the week. It would be another matter if the algorithm,
> although using a non-standard number internally, returned a string.

This is just so much bluster to try to cover the obvious fact that you
failed to read the documentation before claiming the function was wrong.
If your real complaint was that I numbered the days in the wrong order,
you should have said so in the first place.

In my first reply I tried to be reasonable; I said you could feel free
to change the code if you prefer, but don't forget to change the comment
to match.

Since then you have demonstrated that you have no interest in being
reasonable. I have no interest in arguing with unreasonable people.

Annie

unread,
Sep 2, 2003, 4:42:12 AM9/2/03
to
**** Post for FREE via your newsreader at post.usenet.com ****


On 2003-09-02 dse...@no.such.host (Dave Seaman) said:

> This is just so much bluster to try to cover the obvious fact that
> you failed to read the documentation before claiming the function
> was wrong. If your real complaint was that I numbered the days in
> the wrong order, you should have said so in the first place.
>
> In my first reply I tried to be reasonable; I said you could feel
> free to change the code if you prefer, but don't forget to change
> the comment to match.
>
> Since then you have demonstrated that you have no interest in being
> reasonable. I have no interest in arguing with unreasonable people.

_____
As you've undoubtedly discerned from ((( `\
his previous posts in this arena, our _ _`\ )
friend Doctor John is very much a (^ ) )
'company man.' He's quite anal in ~-( )
insisting that everything be done _'((,,,)))
'by the book' in a highly conven- ,-' \_/ `\
tional manner. This is obviously ( , |
his comfort zone. `-.-'`-.-'/|_|
\ / | |
It must be pointed out parenthetically, =()=: / ,' aa
however, that 'convention' literally
never results in innovation.

By the time a concept or procedure has been bureaucratized to
the point of becoming 'conventional,' you can bet your ass
that it's been eviscerated of any 'innovation.'

Innovation is anathema to the bureaucratic mind.

Kevin G. Rhoads

unread,
Sep 2, 2003, 10:28:49 AM9/2/03
to
>This is just so much bluster to try to cover the obvious fact that you
>failed to read the documentation before claiming the function was wrong.

Dr. Stockton did NOT claim the code returned the wrong day of the week,
THAT was another poster, and he made it a question.

Dr. Stockton did point out that an international standard dictates a
1..7 range, which your code does not follow. He is correct in stating
your code provides results which do not comply to the standard. Whether
that is relevant depends upon the person.

That he also cited the Book of Genesis is, as you've stated, irrelevant
to you. The citation of Genesis is irrelevant to me, so I ignore it.
Your commentary upon that citation seems to belie your statement that
it is irrelevant to you. Rather, you seem to take personal offense
from that citation. If it truly is offensive to you, you should state
that. Most people posting here do not try to be intentionally offensive.

I appreciate the effort you have put into this code, and I want to thank
you for posting it.

Sincerely
Kevin

Dave Seaman

unread,
Sep 2, 2003, 1:35:38 PM9/2/03
to
On Tue, 02 Sep 2003 10:28:49 -0400, Kevin G. Rhoads wrote:
>>This is just so much bluster to try to cover the obvious fact that you
>>failed to read the documentation before claiming the function was wrong.

> Dr. Stockton did NOT claim the code returned the wrong day of the week,
> THAT was another poster, and he made it a question.

Ah, I missed that. In that case, my apologies to Dr. Stockton.

> Dr. Stockton did point out that an international standard dictates a
> 1..7 range, which your code does not follow. He is correct in stating
> your code provides results which do not comply to the standard. Whether
> that is relevant depends upon the person.

I didn't claim that my code conformed to any particular standard. I
simply described what it does, and my description is correct. I also
replied (to the original questioner) that he is free to adapt the code as
he prefers. I don't see what the issue is.

> That he also cited the Book of Genesis is, as you've stated, irrelevant
> to you.

That's not exactly what I said, but I did say that I don't base my
algorithms on Genesis.

>The citation of Genesis is irrelevant to me, so I ignore it.

I would have ignored it as well, but for the fact that the posting was
directed at me, and more than half of the argument therein was based on
religion.

> Your commentary upon that citation seems to belie your statement that
> it is irrelevant to you. Rather, you seem to take personal offense
> from that citation.

Was it something I said?

Since the posting was directed at me, and since I was responding to the
parts of the argument that I considered relevant, I wanted to include an
indication of why my response did not address any of the religious
arguments.

>If it truly is offensive to you, you should state
> that. Most people posting here do not try to be intentionally offensive.

I do not consider religion to be offensive (usually). Just irrelevant.

> I appreciate the effort you have put into this code, and I want to thank
> you for posting it.

Nevertheless, I'll think twice before posting it again.

Dr John Stockton

unread,
Sep 2, 2003, 3:33:41 PM9/2/03
to
JRS: In article <3F54A921...@Dartmouth.edu>, seen in
news:comp.os.msdos.misc, Kevin G. Rhoads <Kevin....@Dartmouth.edu>
posted at Tue, 2 Sep 2003 10:28:49 :-

>
>Dr. Stockton did point out that an international standard dictates a
>1..7 range, which your code does not follow. He is correct in stating
>your code provides results which do not comply to the standard.

Indeed, I am always amused to see American engineer- and technician-
types making fools of themselves by having so many standards, and by
avoiding as far as possible compliance with International ones; but I do
like to try to ensure that innocents elsewhere are not deluded thereby.

Consistent use of proper units would, I have heard, saved whatever-it-
was ... MPL? - another aspect of the general situation.

US scientists know better, of course.

Roby

unread,
Sep 3, 2003, 8:34:14 AM9/3/03
to
Dave Seaman wrote:

Time to 'fess up: I was the one who was confused about Dave's code.

Dave was kind enough to point out that I had not read the comment.
Curiously, it was only a few weeks before that I had my annual eye exam.
Perhaps doc needs an eye chart for programmers: /* E */, /* FP */, /* TOZ */

Sorry to have set off WWIII

I wish I'd asked Dave to post an inverse function for that serial date;
i.e.,

int InvSerialDate( long SerialDate, short *Day, short *Month, short *Year )

I've been using an alogorithm that includes floating point for many years.
It works and I haven't had any portability problems yet, but an integer
solution would be better.

Roby

GM

unread,
Sep 10, 2003, 6:56:28 PM9/10/03
to
Sorry, don't have time to look through all the responses, so I don't
know if this has been suggested:

An old technique is to grab the DOS date/time and set it to the file's
date or whatever date you're looking for, then read the the day of the
week from DOS. Finally, put back the saved date and time. I don't know
what algorithm is used by DOS, but at least it'll match whatever DOS
would return about the date.

Brooks Moses

unread,
Sep 10, 2003, 8:46:19 PM9/10/03
to

I would think that this was probably a much better idea back in the days
when computers with DOS date/time routines could be counted on to only
be running one program at a time!

(Ah, I see that this is crossposted to comp.os.msdos.misc; perhaps it's
still mostly true in that world.)

- Brooks

Charles Richmond

unread,
Sep 11, 2003, 4:07:52 AM9/11/03
to
The "day of the week" thing has been done already. If anyone wants
a short description of a working algorithm, email me...

--
+----------------------------------------------------------------+
| Charles and Francis Richmond richmond at plano dot net |
+----------------------------------------------------------------+

Brooks Moses

unread,
Sep 11, 2003, 2:05:59 PM9/11/03
to
Charles Richmond wrote:
> The "day of the week" thing has been done already. If anyone wants
> a short description of a working algorithm, email me...

Several other working algorithms were pointed out in the thread, as well
-- and, additionally, I just now got an email mentioning another; I
believe the author would like it posted here, so I quote:

Alan Miller wrote:
> Has anyone mentioned my web site in this thread.
> I have a file datesub.f90 which does a number of date and day-of-week calculations.
> It is based upon some code from Herman Knoble, and CACM algorithm 398.
>
> At the moment I cannot post to newsgroups because of virus problems on bigpond.
> If you think it appropriate, could you post this message or part of it?
> Thanks.
> My web site address is in my signature below.
>
> Alan Miller
> http://users.bigpond.net.au/amiller
> Retired Statistician


- Brooks

0 new messages