90 187
Assignments Done
99.5%
Successfully Done
In September 2020

# Answer to Question #30540 in Delphi | Pascal for genti feta

Question #30540
how to write a program that makes me possible to know what day is today.for example i say today is the 08th of october,and the program must tell me if it&#039;s monday,tuesday,wednesday,thursday,friday,saturday or sunday...the program must be in pascal..please hel me...
1
2013-05-17T08:55:34-0400
The best way to make such a computation is to use the Julian date system.

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&#039;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&#039;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.

You can use the following code:

program date;
const week: array[1..7] of string = (&#039;Sunday&#039;,&#039;Monday&#039;,&#039;Tuesday&#039;,&#039;Wednesday&#039;,&#039;Thursday&#039;,&#039;Friday&#039;,&#039;Saturday&#039;);
var d, m, y, jd, a, b:real; i:integer;
begin
writeln(&#039;Enter date in format Day Month Year:&#039;);
if (m=1) or (m=2) then
begin
y:=y-1;
m:=m+12;
end;
a:=y/100;
b:=(2-a)+(a/4);
jd:=(365.25*y)+(30.6001*(m+1))+(d+b)+1720994.5+1.5;
i:=round(trunc(((jd/7)-trunc(jd/7))*7));
writeln(week[i+1]);
end.

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!