Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
which day of the week
#1
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
Reply
#2
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
Reply
#3
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 + ...
Reply
#4
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
Reply
#5
(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.
Reply
#6
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 + ...
Reply
#7
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 + ...
Reply
#8
(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.  Big Grin

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.
Reply
#9
(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
Reply
#10
Erik did you check that?
   
b = b + ...
Reply




Users browsing this thread: 2 Guest(s)