Associated Topics || Dr. Math Home || Search Dr. Math

### Pascal Calendar Program

```
Date: 02/12/2002 at 15:20:24
From: Danilo Tiago
Subject: Pascal gregorian calendar program

My Programing teacher gave me a holiday homework: make a program in
Pascal that with a date of our choice give us the day of the week.
Can you help me with that?

Thanks for the attention.
```

```
Date: 02/18/2002 at 11:06:30
From: Doctor Fenton
Subject: Re: Pascal gregorian calendar program

Hi Danilo,

Thanks for writing to Dr. Math. The best way I know to make such a
computation is to use the Julian date system. I'll give you the
algorithm, and it should be straightforward to program.

Determining the Day of the Week from the Calendar Date:

Step 1: Determine the Julian Date (JD) of the calendar date. (The
Julian date is the number of days that have elapsed since noon,
January 1, 4713 B.C. Since it is primarily used by astronomers, it
begins at noon [so that the date doesn't change while they are looking
through their telescopes], and the Julian date of the beginning of a
day at midnight will always be a half-integer.)

Given the year Y, month M, and day D, if M = 1 or 2, then let
y = Y-1 and m = M+12 (this considers January and February as the
13th and 14th months of the previous year).  Otherwise, let y = Y and
m = M.

In the Gregorian calendar (after Oct. 15, 1582), let A = Int(y/100),
and B = 2 - A + Int(A/4).

In the Julian calendar (before Oct. 4, 1582), take B = 0
[Note: many countries didn't adopt the Julian calendar until much
later, so for a historical date, make sure you know which calendar was
being used.]

Then compute the Julian Date

JD = Int(365.25*y)+Int(30.6001*(m+1))+D+B+1720994.5 .

Examples:

1. January 3, 1985.

Since M=1, we take y=1984 and m=13.
A = Int(1984/100)
= Int(19.84)
= 19

and

B = 2 - 19 + Int(19/4)
= 2 - 19 + 4
= -13

Then

JD= Int(365.25*1984)+Int(30.6001*14)+3-13+1720994.5
= Int(724656)+Int(428.4014)+3-13+1720994.5
= 724656 + 428 + 3 - 13 + 1720994.5
= 2446068.5

2. December 3 1993 is JD 2449324.5.

Step 2:  To find the day of the week, add 1.5 to the Julian date
calculated in step 1. Then find the REMAINDER W when (JD+1.5) is
divided by 7. For example, for January 3, 1985, when we divide 2446070
by 7, we get a quotient of  349438 and a remainder of 4:

JD + 1.5 = 7 * 349438 + 4

If the remainder is      the day is
--------------------     ------------
0                    Sunday
1                    Monday
2                    Tuesday
3                    Wednesday
4                    Thursday
5                    Friday
6                    Saturday

so January 3, 1985 was a Thursday.

December 3, 1993 was JD 2449324.5, and JD+1.5 divided by 7 leaves a
remainder of 5, so the day is a Friday.

I hope this helps.  Please write again if you have any questions.

- Doctor Fenton, The Math Forum
http://mathforum.org/dr.math/
```
Associated Topics:
High School Calculators, Computers
High School Puzzles

Search the Dr. Math Library:

 Find items containing (put spaces between keywords):   Click only once for faster results: [ Choose "whole words" when searching for a word like age.] all keywords, in any order at least one, that exact phrase parts of words whole words

Submit your own question to Dr. Math
Math Forum Home || Math Library || Quick Reference || Math Forum Search