Posts: 13
Threads: 4
Joined: Jun 2024
Reputation:
4
This program is used to calculate the day of the week for any day starting from 1 AD.
Code: (Select All)
Code: (Select All)
Dim As Integer y, m, d
Dim a(1 To 12) As _Unsigned _Byte
Input "year,month,day"; y, m, d
If y < 1 Then
Print "Date of invalidity"
End
End If
Data 31,28,31,30,31,30,31,31,30,31,30,31
For i = 1 To 12
Read a(i)
Next i
For i = 1 To m - 1
s = s + a(i)
Next i
n$ = Str$(y)
If Right$(n$, 2) <> "00" Then
If y Mod 4 = 0 And m > 2 Then s = s + 1
Else
If y Mod 400 = 0 And m > 2 Then s = s + 1
End If
If y < 1582 Or (y = 1582 And m <= 10 And d <= 4) Then
y = y - 1
t = (y * 365 + y \ 4 + s + d) Mod 7
Select Case t
Case 0: Print "Friday"
Case 1: Print "Saturday"
Case 2: Print "Sunday"
Case 3: Print "Monday"
Case 4: Print "Tuesday"
Case 5: Print "Wednesday"
Case 6: Print "Thursday"
End Select
ElseIf y = 1582 And m = 10 And 4 < d And d < 15 Then
Print " The date does not exist"
ElseIf y > 1582 Or (y = 1582 And m >= 10 And d > 14) Then
y = y - 1
t = (y * 365 + (y \ 4 - (y \ 100 - y \ 400)) + s + d) Mod 7
Select Case t
Case 0: Print "Sunday"
Case 1: Print "Monday"
Case 2: Print "Tuesday"
Case 3: Print "Wednesday"
Case 4: Print "Thursday"
Case 5: Print "Friday"
Case 6: Print "Saturday"
End Select
End If
Posts: 761
Threads: 35
Joined: Apr 2022
Reputation:
51
Aw man. This reminds me of some code I wrote a long time ago. I think I lost it, though. I had good code for doing that sort of thing. Nice job.
The noticing will continue
Posts: 4,048
Threads: 181
Joined: Apr 2022
Reputation:
231
Reminds me of one of the essential parts of making a calendar.
Anyone want a free calendar for next year? (minus the paper)
b = b + ...
Posts: 419
Threads: 79
Joined: Jul 2022
Reputation:
16
01-02-2025, 02:15 AM
(This post was last modified: 01-02-2025, 02:43 AM by eoredson.)
I can squash that code into 2 lines:
Code: (Select All) Rem determine day of week.
Print "Enter Month,Day,Year";: Input m%, d%, y%
If m% < 3 Then m% = m% + 12: y% = y% - 1
W% = ((13 * m% + 3) \ 5 + d% + y% + y% \ 4 - y% \ 100 + y% \ 400 + 1) Mod 7
Print "Weekday is on: ";
If W% = 0 Then Print "Sunday"
If W% = 1 Then Print "Monday"
If W% = 2 Then Print "Tuesday"
If W% = 3 Then Print "Wednesday"
If W% = 4 Then Print "Thursday"
If W% = 5 Then Print "Friday"
If W% = 6 Then Print "Saturday"
End
Posts: 2,309
Threads: 236
Joined: Apr 2022
Reputation:
117
(01-02-2025, 02:15 AM)eoredson Wrote: I can squash that code into 2 lines:
Code: (Select All) Rem determine day of week.
Print "Enter Month,Day,Year";: Input m%, d%, y%
If m% < 3 Then m% = m% + 12: y% = y% - 1
W% = ((13 * m% + 3) \ 5 + d% + y% + y% \ 4 - y% \ 100 + y% \ 400 + 1) Mod 7
Print "Weekday is on: ";
If W% = 0 Then Print "Sunday"
If W% = 1 Then Print "Monday"
If W% = 2 Then Print "Tuesday"
If W% = 3 Then Print "Wednesday"
If W% = 4 Then Print "Thursday"
If W% = 5 Then Print "Friday"
If W% = 6 Then Print "Saturday"
End
We'z up ta squishing things? I love'z squishing things! Stompity, stomp, stomp, stomp....Take that, varmint!
Code: (Select All)
Rem determine day of week.
map$ = "Sunday Monday Tuesday Wednesday Thursday Friday Saturday"
Print "Enter Month,Day,Year";: Input m%, d%, y%
If m% < 3 Then m% = m% + 12: y% = y% - 1
W% = ((13 * m% + 3) \ 5 + d% + y% + y% \ 4 - y% \ 100 + y% \ 400 + 1) Mod 7
Print "Weekday is on: "; RTrim$(Mid$(map$, 10 * W% + 1, 10))
End
- Sam
Shoot first and shoot people who ask questions, later.
Posts: 4,048
Threads: 181
Joined: Apr 2022
Reputation:
231
I don't think Eric and Pete are accounting for the change in 1582 as macalwen has.
I tried to find the first day of Jan 1, 0 AD and Pete says Sunday because Eriks say Sunday I bet and when I disable macalwen's check for years less than 1, he gives me Friday. That is the way to start off an era, going into a weekend!
b = b + ...
Posts: 4,048
Threads: 181
Joined: Apr 2022
Reputation:
231
01-02-2025, 05:55 AM
(This post was last modified: 01-02-2025, 05:57 AM by bplus.)
Columbus discovered America, at least the Bahamas, Oct 12, 1492.
What day was that?
Pete and probably Eirk's say Wedesday, Macalwen says Friday again. Bplus says best to diccover new lands on Fridays.
BTW Google's AI says it was on a Thursday!
Google must of averaged macalwen's and Pete's answers.
b = b + ...
Posts: 2,735
Threads: 331
Joined: Apr 2022
Reputation:
227
01-02-2025, 06:18 AM
(This post was last modified: 01-02-2025, 06:21 AM by SMcNeill.)
(01-02-2025, 05:55 AM)bplus Wrote: Columbus discovered America, at least the Bahamas, Oct 12, 1492.
What day was that?
Pete and probably Eirk's say Wedesday, Macalwen says Friday again. Bplus says best to diccover new lands on Fridays.
BTW Google's AI says it was on a Thursday!
Google must of averaged macalwen's and Pete's answers.
And yet, all the calendars say it was a Monday.. https://jleic-docdb.jlab.org/cgi-bin/pub...2&month=10
Ahh... Here's the reason why.
https://www.dayoftheweek.org/?m=October&...1492&go=Go
Quote:A note to students, teachers, scholars and anyone else passionate about this topic. As stated in the front page, this website is using the Gregorian calendar as the basis for all “day of the week” computation whether or not the Gregorian calendar is relevant for the date in question (October 12, 1492). Educators should point out the primary reason why Pope Gregory XIII introduced a new calendar system in October 1582. That is, to make the computation for the annual date of Easter more accurate since it is the foundation of the Christian faith.
Even with that purpose in mind, the Gregorian calendar too will become out of sync. It has a known approximation error of about one day for every 7,700 years assuming a constant time interval between vernal equinoxes (which is not true). This is better compared to the one day for every 128 years error of the Julian calendar.
Posts: 419
Threads: 79
Joined: Jul 2022
Reputation:
16
01-02-2025, 06:32 AM
(This post was last modified: 01-02-2025, 06:40 AM by eoredson.)
(01-02-2025, 05:55 AM)bplus Wrote: Columbus discovered America, at least the Bahamas, Oct 12, 1492.
What day was that?
Pete and probably Eirk's say Wedesday, Macalwen says Friday again. Bplus says best to diccover new lands on Fridays.
BTW Google's AI says it was on a Thursday!
Google must of averaged macalwen's and Pete's answers. Sure, then all you have to do is modify it to:
Code: (Select All) Rem determine day of week.
m$ = "Sunday Monday Tuesday WednesdayThursday Friday Saturday"
m2$ = "Friday Saturday Sunday Monday Tuesday WednesdayThursday"
Print "Enter Month,Day,Year";: Input m%, d%, y%
If m% < 3 Then m% = m% + 12: y% = y% - 1
W% = ((13 * m% + 3) \ 5 + d% + y% + y% \ 4 - y% \ 100 + y% \ 400 + 1) Mod 7
If y% < 1582 Or (y% = 1582 And m% <= 10 And d% <= 4) Then
Print "Weekday is on: "; Mid$(m2$, 9 * W% + 1, 9)
Else
Print "Weekday is on: "; Mid$(m$, 9 * W% + 1, 9)
End If
End
Posts: 4,048
Threads: 181
Joined: Apr 2022
Reputation:
231
Erik did you check that?
b = b + ...
|