Answer to Question #30540 in Delphi | Pascal for genti feta
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
Then compute the Julian Date
& JD = Int(365.25*y)+Int(30.6001*(m+1))+D+B+1720994.5 .
1. January 3, 1985.
Since M=1, we take y=1984 and m=13. &
& A = Int(1984/100)
& B = 2 - 19 + Int(19/4)
= 2 - 19 + 4
& JD= Int(365.25*1984)+Int(30.6001*14)+3-13+1720994.5
= 724656 + 428 + 3 - 13 + 1720994.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.
You can use the following code:
const week: array[1..7] of string = ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
var d, m, y, jd, a, b:real; i:integer;
writeln('Enter date in format Day Month Year:');
readln(d, m, y);
if (m=1) or (m=2) then
Need a fast expert's response?Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!