Weekday and Leap Year Calculator - SierraKen - 10-14-2024
Today I was just goofing around with the calendar making program I made awhile back, and decided to make a much simpler app that tells you what weekday it is for a given date. I also added a leap year calculator on it as well. Then afterward I noticed that Steve and Bplus and others have made similar ones, so oh well. At least this will be easier for programmers to learn with than my calendar making program.
Code: (Select All)
'Weekday and Leap Year Calculator by SierraKen
'October 14, 2024
'This app tells you what weekday of the year a date falls on or if you want to see if a certain year has a Leap Year.
'It can use anywhere from 1753 A.D. to 9999 A.D because 1753 is when the Gregorian Calendar started.
'Most of this code is taken from my Calendar Maker on the QB64 Phoenix forum.
'Thank you to the guys on forum for the help!
Dim leap As Single
Dim dd As Single
Dim olddd As Single
Dim mm As Single
Dim oldmm As Single
Dim yy As Single
Dim oldyy As Single
Dim days As Single
Dim weekday As Single
_Title "Weekday and Leap Year Calculator by SierraKen"
start:
leap = 0: dd = 0: mm = 0: yy = 0: days = 0: weekday = 0: oldyy = 0: menu = 0
ag$ = ""
Cls
Print: Print
Print " Weekday and Leap Year Calculator by SierraKen"
Print: Print: Print
Print "(1) Calculate Weekday"
Print "(2) Calculate Leap Year"
Print "(3) Quit"
Print: Print
Print "Press 1, 2, or 3."
themenu:
menu$ = InKey$
If menu$ = "1" Then GoTo month:
If menu$ = "2" Then GoTo leapyear:
If menu$ = "3" Then End
GoTo themenu:
month:
Print
Input "Month (1-12): ", mm
If mm > 12 Or mm < 1 Or Int(mm) <> mm Then Print "Months must be between 1 and 12, try again.": Print: Print: GoTo month:
Print
day:
Input "Day (1-31): ", dd
Print
Input "Year (1753-9999): ", yy
If yy < 1753 Or yy > 9999 Then Print "Year must be between 1753 and 9999. Try again.": Print: Print: GoTo month:
'Calculate to see if it's a Leap Year.
If mm <> 2 Then GoTo nex:
If yy / 400 = Int(yy / 400) Then leap = 1: GoTo more:
If yy / 4 = Int(yy / 4) Then leap = 1
If yy / 100 = Int(yy / 100) Then leap = 0
'Get the number of days for each month.
more:
If leap = 1 Then days = 29
If leap = 0 Then days = 28
GoTo weekday:
nex:
If mm = 1 Then days = 31
If mm = 3 Then days = 31
If mm = 4 Then days = 30
If mm = 5 Then days = 31
If mm = 6 Then days = 30
If mm = 7 Then days = 31
If mm = 8 Then days = 31
If mm = 9 Then days = 30
If mm = 10 Then days = 31
If mm = 11 Then days = 30
If mm = 12 Then days = 31
weekday:
If dd < 1 Or dd <> Int(dd) Or dd > days Then Print "Days must be between 1 and " + Str$(days) + " on that month. Try again.": Print: Print: GoTo day:
If mm = 1 Then month$ = "January"
If mm = 2 Then month$ = "February"
If mm = 3 Then month$ = "March"
If mm = 4 Then month$ = "April"
If mm = 5 Then month$ = "May"
If mm = 6 Then month$ = "June"
If mm = 7 Then month$ = "July"
If mm = 8 Then month$ = "August"
If mm = 9 Then month$ = "September"
If mm = 10 Then month$ = "October"
If mm = 11 Then month$ = "November"
If mm = 12 Then month$ = "December"
oldyy = yy
oldmm = mm
olddd = dd
GetDay mm, dd, yy, weekday
yy = oldyy
mm = oldmm
dd = olddd
If weekday = 1 Then weekday$ = "Sunday"
If weekday = 2 Then weekday$ = "Monday"
If weekday = 3 Then weekday$ = "Tuesday"
If weekday = 4 Then weekday$ = "Wednesday"
If weekday = 5 Then weekday$ = "Thursday"
If weekday = 6 Then weekday$ = "Friday"
If weekday = 0 Then weekday$ = "Saturday"
'--------------------------------------------------------------------------------------------------
Print: Print
Print month$ + " " + Str$(dd) + ", " + Str$(yy) + " falls on a " + weekday$ + "."
'--------------------------------------------------------------------------------------------------
Print: Print: Print
Print "Press M to go to menu or Esc to quit."
againn:
ag$ = InKey$
If ag$ = "m" Or ag$ = "M" Then GoTo start:
If ag$ = Chr$(27) Then End
GoTo againn:
leapyear:
Input "Year (1753-9999): ", yy
If yy < 1753 Or yy > 9999 Then Print "Year must be between 1753 and 9999. Try again.": Print: Print: GoTo leapyear:
'Calculate to see if it's a Leap Year.
If yy / 400 = Int(yy / 400) Then leap = 1: GoTo more2:
If yy / 4 = Int(yy / 4) Then leap = 1
If yy / 100 = Int(yy / 100) Then leap = 0
'Get the number of days for each month.
more2:
Print: Print
If leap = 1 Then Print Str$(yy) + " does have a Leap Year."
If leap = 0 Then Print Str$(yy) + " does not have a Leap Year."
Print: Print: Print
Print "Press M to go menu or Esc to quit."
again:
ag$ = InKey$
If ag$ = "m" Or ag$ = "M" Then GoTo start:
If ag$ = Chr$(27) Then End
GoTo again:
'This section gets the right weekday.
Sub GetDay (mm, dd, yy, weekday) 'use 4 digit year
'From Zeller's congruence: https://en.wikipedia.org/wiki/Zeller%27s_congruence
If mm < 3 Then yy = yy - 1
If mm < 3 Then mm = mm + 12
century = yy Mod 100
zerocentury = yy \ 100
weekday = (dd + Int(13 * (mm + 1) / 5) + century + Int(century / 4) + Int(zerocentury / 4) + 5 * zerocentury) Mod 7
End Sub
|