Author Topic: Weekday Finder  (Read 9483 times)

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Weekday Finder
« on: August 01, 2019, 11:55:06 pm »
Hi all,

This is another program that I've always wanted to make but never did. It's a weekday finder for any date for any year in the Gregorian Calendar, which is after September 14, 1752. Don't worry, it detects if you try an earlier date. But it doesn't detect if you say a date wrong, like a 31st day of a month that doesn't have 31 days. I thought about adding that, but that's a lot of code, especially for Leap Year, that the user never sees. So I mostly just stuck with the basics. I found what's called Zeller's Rule equation online tonight and used that. For like 1 or 2 hours I wondered why it wouldn't work until I added some PRINT commands for my variables to check them all and I had no idea that LEFT$(y$,3) is needed just for the 2 first numbers of the year, which is y$. I still don't know why it needs 3 and not just 2. But it does and now it works fine. :) Please tell me what you think, thanks. By the way, I know there's countless of these things on websites already, but I just wanted to make my own. Plus now that it's in QB64 code, people are free to use my code in any of their own programs. I don't know if any of you have made this before, but possibly.

(Note: I added more below, so keep scrolling, thanks.)

Code: QB64: [Select]
  1. 'This program uses Zeller's Rule equation to determine what day of the week for any given day on the Gregorian Calander, which is after Sept. 14, 1752.
  2. 'I don't know how the equation works, but I decided to try it and it works great!
  3. 'This program was made on August 1, 2019... which was a Thursday. :)
  4. 'Feel free to use this code in your own programs.
  5. 'Made by Ken G.
  6. 'Freeware only.
  7.  
  8. _TITLE "Day of the Week Finder"
  9. start:
  10. PRINT "                             Day of the Week Finder"
  11. PRINT "                                   By Ken G."
  12. PRINT "                 After September 14, 1752 because that's"
  13. PRINT "                 when the Gregorian Calendar started."
  14. again:
  15. INPUT "                 Year: ", y
  16. IF y < 1752 THEN PRINT "Year must be after 1751.": GOTO again:
  17. again2:
  18. INPUT "                 Month (1-12): ", m
  19. IF m < 1 OR m > 12 THEN PRINT "Type a month 1-12 only.": GOTO again2:
  20. again3:
  21. INPUT "                 Day: ", k
  22. IF k > 31 OR k < 1 THEN PRINT "Days must be 1-31 only.": GOTO again3:
  23. IF y = 1752 AND m <= 9 AND d < 14 THEN PRINT "Your date is too early to calculate on the Gregorian Calendar, try again.": GOTO again:
  24.  
  25. 'Months
  26. 'The months start on March 1 so Leap Year will be the last day of the year, which is why Jan. and Feb. are actually the year before.
  27. mm = m - 2
  28. IF m = 1 THEN mm = 11: y = y - 1
  29. IF m = 2 THEN mm = 12: y = y - 1
  30.  
  31. 'Full Year.
  32. y$ = STR$(y)
  33.  
  34. 'Last 2 digits of year.
  35. yy$ = RIGHT$(y$, 2)
  36. yy = VAL(yy$)
  37.  
  38. 'Century
  39. c$ = LEFT$(y$, 3)
  40. c = VAL(c$)
  41.  
  42. 'Here is Zeller's Rule equation.
  43.  
  44. weekday = (k + INT(((13 * mm) - 1) / 5) + yy + INT(yy / 4) + INT(c / 4) - (2 * c)) MOD 7
  45.  
  46. IF weekday = 0 THEN w$ = "Sunday"
  47. IF weekday = 1 THEN w$ = "Monday"
  48. IF weekday = 2 THEN w$ = "Tuesday"
  49. IF weekday = 3 THEN w$ = "Wednesday"
  50. IF weekday = 4 THEN w$ = "Thursday"
  51. IF weekday = 5 THEN w$ = "Friday"
  52. IF weekday = 6 THEN w$ = "Saturday"
  53.  
  54.  
  55. PRINT "                 Your Day Of The Week Is: "; w$
  56. INPUT "                 Again (Y/N)"; ag$
  57. IF LEFT$(ag$, 1) = "y" OR LEFT$(ag$, 1) = "Y" THEN GOTO start:
  58.  
« Last Edit: August 02, 2019, 02:03:56 am by SierraKen »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Weekday Finder
« Reply #1 on: August 02, 2019, 12:17:35 am »
Quote
For like 1 or 2 hours I wondered why it wouldn't work until I added some PRINT commands for my variables to check them all and I had no idea that LEFT$(y$,3) is needed just for the 2 first numbers of the year, which is y$. I still don't know why it needs 3 and not just 2. But it does and now it works fine. :)

Code: QB64: [Select]
  1. REM the STR$(Positive number) leaves a space on left of number where a - neg sign would go if it were negative.
  2.     INPUT "Enter a year > "; y
  3.     y$ = STR$(y)
  4.     PRINT "You entered *"; STR$(y); "*"
  5.     PRINT "Left$(str$(y), 2) = *"; LEFT$(STR$(y), 2); "*"
  6.     PRINT
  7.  

Could of saved a step by:
Code: QB64: [Select]
  1. INPUT "Enter a year > "; y$

That is quite a calculation for week day! :)

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Weekday Finder
« Reply #2 on: August 02, 2019, 12:28:57 am »
Thanks B+, but I actually had to split the whole year from century and last 2 digits and use it all.
Yeah, I went to a couple of math teaching websites to figure it out. :)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Weekday Finder
« Reply #3 on: August 02, 2019, 01:01:27 am »
Thanks B+, but I actually had to split the whole year from century and last 2 digits and use it all.
Yeah, I went to a couple of math teaching websites to figure it out. :)

Code: QB64: [Select]
  1.     INPUT "Enter a year > "; y$
  2.     c = VAL(LEFT$(y$, 2))
  3.     yy = VAL(RIGHT$(y$, 2))
  4.     PRINT c, yy
  5.  

If you take the year in with a string, you don't have to worry about str$(y), you save a step.
« Last Edit: August 02, 2019, 01:03:52 am by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Weekday Finder
« Reply #4 on: August 02, 2019, 01:09:36 am »
Yes, but I also had to use the year as a variable as Y in this section:
I also have some IF/THEN statements so people can't go under or over the limits of the program.

Code: QB64: [Select]
  1. 'Months
  2. 'The months start on March 1 so Leap Year will be the last day of the year, which is why Jan. and Feb. are actually the year before.
  3. mm = m - 2
  4. IF m = 1 THEN mm = 11: y = y - 1
  5. IF m = 2 THEN mm = 12: y = y - 1
  6.  
« Last Edit: August 02, 2019, 01:15:46 am by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Weekday Finder
« Reply #5 on: August 02, 2019, 01:12:01 am »
I just added some more text so the people know not to go over the date December 31, 9999. It can't use a year with 5 digits. LOL
So here it is:

(Note: There's a better one below this one, which has detection of any bad dates, even Leap Year, so keep scrolling, thanks.)

Code: QB64: [Select]
  1. 'This program uses Zeller's Rule equation to determine what day of the week for any given day on the Gregorian Calander, which is after Sept. 14, 1752.
  2. 'I don't know how the equation works, but I decided to try it and it works great!
  3. 'This program was made on August 1, 2019... which was a Thursday. :)
  4. 'Feel free to use this code in your own programs.
  5. 'Made by Ken G.
  6. 'Freeware only.
  7.  
  8. _TITLE "Day of the Week Finder"
  9. start:
  10. PRINT "                             Day of the Week Finder"
  11. PRINT "                                   By Ken G."
  12. PRINT "                 After September 14, 1752 because that's"
  13. PRINT "                 when the Gregorian Calendar started."
  14. PRINT "                 The highest date for this program"
  15. PRINT "                 is December 31, 9999."
  16. again:
  17. INPUT "                 Year: ", y
  18. IF y < 1752 THEN PRINT "Year must be after 1751.": GOTO again:
  19. IF y > 9999 THEN PRINT "The year cannot be over 9999, try again.": GOTO again:
  20. again2:
  21. INPUT "                 Month (1-12): ", m
  22. IF m < 1 OR m > 12 THEN PRINT "Type a month 1-12 only.": GOTO again2:
  23. again3:
  24. INPUT "                 Day: ", k
  25. IF k > 31 OR k < 1 THEN PRINT "Days must be 1-31 only.": GOTO again3:
  26. IF y = 1752 AND m <= 9 AND d < 14 THEN PRINT "Your date is too early to calculate on the Gregorian Calendar, try again.": GOTO again:
  27.  
  28. 'Months
  29. 'The months start on March 1 so Leap Year will be the last day of the year, which is why Jan. and Feb. are actually the year before.
  30. mm = m - 2
  31. IF m = 1 THEN mm = 11: y = y - 1
  32. IF m = 2 THEN mm = 12: y = y - 1
  33.  
  34. 'Full Year.
  35. y$ = STR$(y)
  36.  
  37. 'Last 2 digits of year.
  38. yy$ = RIGHT$(y$, 2)
  39. yy = VAL(yy$)
  40.  
  41. 'Century
  42. c$ = LEFT$(y$, 3)
  43. c = VAL(c$)
  44.  
  45. 'Here is Zeller's Rule equation.
  46.  
  47. weekday = (k + INT(((13 * mm) - 1) / 5) + yy + INT(yy / 4) + INT(c / 4) - (2 * c)) MOD 7
  48.  
  49. IF weekday = 0 THEN w$ = "Sunday"
  50. IF weekday = 1 THEN w$ = "Monday"
  51. IF weekday = 2 THEN w$ = "Tuesday"
  52. IF weekday = 3 THEN w$ = "Wednesday"
  53. IF weekday = 4 THEN w$ = "Thursday"
  54. IF weekday = 5 THEN w$ = "Friday"
  55. IF weekday = 6 THEN w$ = "Saturday"
  56.  
  57.  
  58. PRINT "                 Your Day Of The Week Is: "; w$
  59. INPUT "                 Again (Y/N)"; ag$
  60. IF LEFT$(ag$, 1) = "y" OR LEFT$(ag$, 1) = "Y" THEN GOTO start:
  61.  
« Last Edit: August 02, 2019, 02:05:00 am by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Weekday Finder
« Reply #6 on: August 02, 2019, 02:03:31 am »
Well, I changed my mind and added a way for the program to detect bad dates for every month and also Leap Years. :) Wasn't too hard. :)
So here is a much better version. :)

I want to say thank you to everyone who is always patient with me on my programs. I will try to be more patient with myself when I program and give myself more time to think over things and program more with newer ideas, before I post as much as I've done. I know it's a bit much, etc.

(Don't use this code, use one of the others that people have posted instead, there's a problem with this.)

Code: QB64: [Select]
  1. 'This program uses Zeller's Rule equation to determine what day of the week for any given day on the Gregorian Calander, which is after Sept. 14, 1752.
  2. 'I don't know how the equation works, but I decided to try it and it works great!
  3. 'This program was made on August 1, 2019... which was a Thursday. :)
  4. 'Feel free to use this code in your own programs.
  5. 'Made by Ken G.
  6. 'Freeware only.
  7.  
  8. _TITLE "Day of the Week Finder"
  9. start:
  10. PRINT "                             Day of the Week Finder"
  11. PRINT "                                   By Ken G."
  12. PRINT "                 After September 14, 1752 because that's"
  13. PRINT "                 when the Gregorian Calendar started."
  14. PRINT "                 The highest date for this program"
  15. PRINT "                 is December 31, 9999."
  16. again:
  17. INPUT "                 Year: ", y
  18. IF y < 1752 THEN PRINT "Year must be after 1751.": GOTO again:
  19. IF y > 9999 THEN PRINT "The year cannot be over 9999, try again.": GOTO again:
  20. IF y <> INT(y) THEN PRINT "Cannot use decimals, try again.": GOTO again:
  21. again2:
  22. INPUT "                 Month (1-12): ", m
  23. IF m < 1 OR m > 12 THEN PRINT "Type a month 1-12 only.": GOTO again2:
  24. IF m <> INT(m) THEN PRINT "Cannot use decimals, try again.": GOTO again2:
  25. again3:
  26. INPUT "                 Day: ", k
  27. IF k > 31 OR k < 1 THEN PRINT "Days must be 1-31 only.": GOTO again3:
  28. IF k <> INT(k) THEN PRINT "Cannot use decimals, try again.": GOTO again3:
  29. IF y = 1752 AND m <= 9 AND d < 14 THEN PRINT "Your date is too early to calculate on the Gregorian Calendar, try again.": GOTO again:
  30.  
  31. IF m = 1 AND k > 31 THEN PRINT "January has 31 days, try again.": GOTO again3:
  32. IF m = 2 THEN
  33.     IF y / 400 = INT(y / 400) THEN leap = 1: GOTO nexone:
  34.     IF y / 4 = INT(y / 4) THEN leap = 1
  35.     IF y / 100 = INT(y / 100) THEN leap = 0
  36.     nexone:
  37.     IF leap = 1 AND k > 29 THEN PRINT "This is a Leap Year, so the last day of Feb. is the 29th, try again.": GOTO again3:
  38.     IF leap = 0 AND k > 28 THEN PRINT "This is not a Leap Year, so the last day of Feb. is the 28th, try again.": GOTO again3:
  39. IF m = 3 AND k > 31 THEN PRINT "March has 31 days, try again.": GOTO again3:
  40. IF m = 4 AND k > 30 THEN PRINT "April only has 30 days, try again.": GOTO again3:
  41. IF m = 5 AND k > 31 THEN PRINT "May has 31 days, try again.": GOTO again3:
  42. IF m = 6 AND k > 30 THEN PRINT "June only has 30 days, try again.": GOTO again3:
  43. IF m = 7 AND k > 31 THEN PRINT "July has 31 days, try again.": GOTO again3:
  44. IF m = 8 AND k > 31 THEN PRINT "August has 31 days, try again.": GOTO again3:
  45. IF m = 9 AND k > 30 THEN PRINT "September only has 30 days, try again.": GOTO again3:
  46. IF m = 10 AND k > 31 THEN PRINT "October has 31 days, try again.": GOTO again3:
  47. IF m = 11 AND k > 30 THEN PRINT "November only has 30 days, try again.": GOTO again3:
  48. IF m = 12 AND k > 31 THEN PRINT "December has 31 days, try again.": GOTO again3:
  49.  
  50.  
  51. 'Months
  52. 'The months start on March 1 so Leap Year will be the last day of the year, which is why Jan. and Feb. are actually the year before.
  53. mm = m - 2
  54. IF m = 1 THEN mm = 11: y = y - 1
  55. IF m = 2 THEN mm = 12: y = y - 1
  56.  
  57. 'Full Year.
  58. y$ = STR$(y)
  59.  
  60. 'Last 2 digits of year.
  61. yy$ = RIGHT$(y$, 2)
  62. yy = VAL(yy$)
  63.  
  64. 'Century
  65. c$ = LEFT$(y$, 3)
  66. c = VAL(c$)
  67.  
  68. 'Here is Zeller's Rule equation.
  69.  
  70. weekday = (k + INT(((13 * mm) - 1) / 5) + yy + INT(yy / 4) + INT(c / 4) - (2 * c)) MOD 7
  71.  
  72. IF weekday = 0 THEN w$ = "Sunday"
  73. IF weekday = 1 THEN w$ = "Monday"
  74. IF weekday = 2 THEN w$ = "Tuesday"
  75. IF weekday = 3 THEN w$ = "Wednesday"
  76. IF weekday = 4 THEN w$ = "Thursday"
  77. IF weekday = 5 THEN w$ = "Friday"
  78. IF weekday = 6 THEN w$ = "Saturday"
  79.  
  80.  
  81. PRINT "                 Your Day Of The Week Is: "; w$
  82. INPUT "                 Again (Y/N)"; ag$
  83. IF LEFT$(ag$, 1) = "y" OR LEFT$(ag$, 1) = "Y" THEN GOTO start:
  84.  
  85.  

« Last Edit: August 04, 2019, 11:26:40 am by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Weekday Finder
« Reply #7 on: August 02, 2019, 02:21:55 am »
I found a bad error in the last ones. I forgot to check the 1752 year before the date the Gregorian Calendar started, so I fixed it.

So here is this one:
 
(Don't use this code, there's a problem with it. Use one of the others instead that people have posted.)

Code: QB64: [Select]
  1. 'This program uses Zeller's Rule equation to determine what day of the week for any given day on the Gregorian Calander, which is after Sept. 14, 1752.
  2. 'I don't know how the equation works, but I decided to try it and it works great!
  3. 'This program was made on August 1, 2019... which was a Thursday. :)
  4. 'Feel free to use this code in your own programs.
  5. 'Made by Ken G.
  6. 'Freeware only.
  7.  
  8. _TITLE "Day of the Week Finder"
  9. start:
  10. PRINT "                             Day of the Week Finder"
  11. PRINT "                                   By Ken G."
  12. PRINT "                 After September 13, 1752 because that's"
  13. PRINT "                 when the Gregorian Calendar started."
  14. PRINT "                 The highest date for this program"
  15. PRINT "                 is December 31, 9999."
  16. again:
  17. INPUT "                 Year: ", y
  18. IF y < 1752 THEN PRINT "Year must be after 1751.": GOTO again:
  19. IF y > 9999 THEN PRINT "The year cannot be over 9999, try again.": GOTO again:
  20. IF y <> INT(y) THEN PRINT "Cannot use decimals, try again.": GOTO again:
  21. again2:
  22. INPUT "                 Month (1-12): ", m
  23. IF m < 1 OR m > 12 THEN PRINT "Type a month 1-12 only.": GOTO again2:
  24. IF m <> INT(m) THEN PRINT "Cannot use decimals, try again.": GOTO again2:
  25. again3:
  26. INPUT "                 Day: ", k
  27. IF k > 31 OR k < 1 THEN PRINT "Days must be 1-31 only.": GOTO again3:
  28. IF k <> INT(k) THEN PRINT "Cannot use decimals, try again.": GOTO again3:
  29. IF y = 1752 AND m = 9 AND k < 14 THEN PRINT "Your date is too early to calculate on the Gregorian Calendar, try again.": GOTO again:
  30. IF y = 1752 AND m < 9 THEN PRINT "Your date is too early to calculate on the Gregorian Calendar, try again.": GOTO again:
  31.  
  32. IF m = 1 AND k > 31 THEN PRINT "January has 31 days, try again.": GOTO again3:
  33. IF m = 2 THEN
  34.     IF y / 400 = INT(y / 400) THEN leap = 1: GOTO nexone:
  35.     IF y / 4 = INT(y / 4) THEN leap = 1
  36.     IF y / 100 = INT(y / 100) THEN leap = 0
  37.     nexone:
  38.     IF leap = 1 AND k > 29 THEN PRINT "This is a Leap Year, so the last day of Feb. is the 29th, try again.": GOTO again3:
  39.     IF leap = 0 AND k > 28 THEN PRINT "This is not a Leap Year, so the last day of Feb. is the 28th, try again.": GOTO again3:
  40. IF m = 3 AND k > 31 THEN PRINT "March has 31 days, try again.": GOTO again3:
  41. IF m = 4 AND k > 30 THEN PRINT "April only has 30 days, try again.": GOTO again3:
  42. IF m = 5 AND k > 31 THEN PRINT "May has 31 days, try again.": GOTO again3:
  43. IF m = 6 AND k > 30 THEN PRINT "June only has 30 days, try again.": GOTO again3:
  44. IF m = 7 AND k > 31 THEN PRINT "July has 31 days, try again.": GOTO again3:
  45. IF m = 8 AND k > 31 THEN PRINT "August has 31 days, try again.": GOTO again3:
  46. IF m = 9 AND k > 30 THEN PRINT "September only has 30 days, try again.": GOTO again3:
  47. IF m = 10 AND k > 31 THEN PRINT "October has 31 days, try again.": GOTO again3:
  48. IF m = 11 AND k > 30 THEN PRINT "November only has 30 days, try again.": GOTO again3:
  49. IF m = 12 AND k > 31 THEN PRINT "December has 31 days, try again.": GOTO again3:
  50.  
  51.  
  52. 'Months
  53. 'The months start on March 1 so Leap Year will be the last day of the year, which is why Jan. and Feb. are actually the year before.
  54. mm = m - 2
  55. IF m = 1 THEN mm = 11: y = y - 1
  56. IF m = 2 THEN mm = 12: y = y - 1
  57.  
  58. 'Full Year.
  59. y$ = STR$(y)
  60.  
  61. 'Last 2 digits of year.
  62. yy$ = RIGHT$(y$, 2)
  63. yy = VAL(yy$)
  64.  
  65. 'Century
  66. c$ = LEFT$(y$, 3)
  67. c = VAL(c$)
  68.  
  69. 'Here is Zeller's Rule equation.
  70.  
  71. weekday = (k + INT(((13 * mm) - 1) / 5) + yy + INT(yy / 4) + INT(c / 4) - (2 * c)) MOD 7
  72.  
  73. IF weekday = 0 THEN w$ = "Sunday"
  74. IF weekday = 1 THEN w$ = "Monday"
  75. IF weekday = 2 THEN w$ = "Tuesday"
  76. IF weekday = 3 THEN w$ = "Wednesday"
  77. IF weekday = 4 THEN w$ = "Thursday"
  78. IF weekday = 5 THEN w$ = "Friday"
  79. IF weekday = 6 THEN w$ = "Saturday"
  80.  
  81.  
  82. PRINT "                 Your Day Of The Week Is: "; w$
  83. INPUT "                 Again (Y/N)"; ag$
  84. IF LEFT$(ag$, 1) = "y" OR LEFT$(ag$, 1) = "Y" THEN GOTO start:
  85.  
  86.  

« Last Edit: August 04, 2019, 11:25:36 am by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Weekday Finder
« Reply #8 on: August 02, 2019, 02:22:53 am »
Well, I changed my mind and added a way for the program to detect bad dates for every month and also Leap Years. :) Wasn't too hard. :)
So here is a much better version. :)

I want to say thank you to everyone who is always patient with me on my programs. I will try to be more patient with myself when I program and give myself more time to think over things and program more with newer ideas, before I post as much as I've done. I know it's a bit much, etc.

(Note: There's a bad error on this one for the year 1752, so please scroll to the next one, thank you.)

Code: QB64: [Select]
  1. 'This program uses Zeller's Rule equation to determine what day of the week for any given day on the Gregorian Calander, which is after Sept. 14, 1752.
  2. 'I don't know how the equation works, but I decided to try it and it works great!
  3. 'This program was made on August 1, 2019... which was a Thursday. :)
  4. 'Feel free to use this code in your own programs.
  5. 'Made by Ken G.
  6. 'Freeware only.
  7.  
  8. _TITLE "Day of the Week Finder"
  9. start:
  10. PRINT "                             Day of the Week Finder"
  11. PRINT "                                   By Ken G."
  12. PRINT "                 After September 14, 1752 because that's"
  13. PRINT "                 when the Gregorian Calendar started."
  14. PRINT "                 The highest date for this program"
  15. PRINT "                 is December 31, 9999."
  16. again:
  17. INPUT "                 Year: ", y
  18. IF y < 1752 THEN PRINT "Year must be after 1751.": GOTO again:
  19. IF y > 9999 THEN PRINT "The year cannot be over 9999, try again.": GOTO again:
  20. IF y <> INT(y) THEN PRINT "Cannot use decimals, try again.": GOTO again:
  21. again2:
  22. INPUT "                 Month (1-12): ", m
  23. IF m < 1 OR m > 12 THEN PRINT "Type a month 1-12 only.": GOTO again2:
  24. IF m <> INT(m) THEN PRINT "Cannot use decimals, try again.": GOTO again2:
  25. again3:
  26. INPUT "                 Day: ", k
  27. IF k > 31 OR k < 1 THEN PRINT "Days must be 1-31 only.": GOTO again3:
  28. IF k <> INT(k) THEN PRINT "Cannot use decimals, try again.": GOTO again3:
  29. IF y = 1752 AND m <= 9 AND d < 14 THEN PRINT "Your date is too early to calculate on the Gregorian Calendar, try again.": GOTO again:
  30.  
  31. IF m = 1 AND k > 31 THEN PRINT "January has 31 days, try again.": GOTO again3:
  32. IF m = 2 THEN
  33.     IF y / 400 = INT(y / 400) THEN leap = 1: GOTO nexone:
  34.     IF y / 4 = INT(y / 4) THEN leap = 1
  35.     IF y / 100 = INT(y / 100) THEN leap = 0
  36.     nexone:
  37.     IF leap = 1 AND k > 29 THEN PRINT "This is a Leap Year, so the last day of Feb. is the 29th, try again.": GOTO again3:
  38.     IF leap = 0 AND k > 28 THEN PRINT "This is not a Leap Year, so the last day of Feb. is the 28th, try again.": GOTO again3:
  39. IF m = 3 AND k > 31 THEN PRINT "March has 31 days, try again.": GOTO again3:
  40. IF m = 4 AND k > 30 THEN PRINT "April only has 30 days, try again.": GOTO again3:
  41. IF m = 5 AND k > 31 THEN PRINT "May has 31 days, try again.": GOTO again3:
  42. IF m = 6 AND k > 30 THEN PRINT "June only has 30 days, try again.": GOTO again3:
  43. IF m = 7 AND k > 31 THEN PRINT "July has 31 days, try again.": GOTO again3:
  44. IF m = 8 AND k > 31 THEN PRINT "August has 31 days, try again.": GOTO again3:
  45. IF m = 9 AND k > 30 THEN PRINT "September only has 30 days, try again.": GOTO again3:
  46. IF m = 10 AND k > 31 THEN PRINT "October has 31 days, try again.": GOTO again3:
  47. IF m = 11 AND k > 30 THEN PRINT "November only has 30 days, try again.": GOTO again3:
  48. IF m = 12 AND k > 31 THEN PRINT "December has 31 days, try again.": GOTO again3:
  49.  
  50.  
  51. 'Months
  52. 'The months start on March 1 so Leap Year will be the last day of the year, which is why Jan. and Feb. are actually the year before.
  53. mm = m - 2
  54. IF m = 1 THEN mm = 11: y = y - 1
  55. IF m = 2 THEN mm = 12: y = y - 1
  56.  
  57. 'Full Year.
  58. y$ = STR$(y)
  59.  
  60. 'Last 2 digits of year.
  61. yy$ = RIGHT$(y$, 2)
  62. yy = VAL(yy$)
  63.  
  64. 'Century
  65. c$ = LEFT$(y$, 3)
  66. c = VAL(c$)
  67.  
  68. 'Here is Zeller's Rule equation.
  69.  
  70. weekday = (k + INT(((13 * mm) - 1) / 5) + yy + INT(yy / 4) + INT(c / 4) - (2 * c)) MOD 7
  71.  
  72. IF weekday = 0 THEN w$ = "Sunday"
  73. IF weekday = 1 THEN w$ = "Monday"
  74. IF weekday = 2 THEN w$ = "Tuesday"
  75. IF weekday = 3 THEN w$ = "Wednesday"
  76. IF weekday = 4 THEN w$ = "Thursday"
  77. IF weekday = 5 THEN w$ = "Friday"
  78. IF weekday = 6 THEN w$ = "Saturday"
  79.  
  80.  
  81. PRINT "                 Your Day Of The Week Is: "; w$
  82. INPUT "                 Again (Y/N)"; ag$
  83. IF LEFT$(ag$, 1) = "y" OR LEFT$(ag$, 1) = "Y" THEN GOTO start:
  84.  
  85.  

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: Weekday Finder
« Reply #9 on: August 02, 2019, 03:49:58 am »

Could of saved a step by:


bplus!!! This is the most egregious grammatical error (usually perpetrated by youngsters).

"Could have saved a step by:"

which has short form "Could've saved a step by:"

and which therefore sounds as if there is an "of" in the sentence.  But there most definitely is not.



Offline euklides

  • Forum Regular
  • Posts: 128
    • View Profile
Re: Weekday Finder
« Reply #10 on: August 02, 2019, 04:49:11 am »
This my version of the weekday finder (an gives julian date too, so you can also calculate number of days between two dates )...

Works for dates after october,15, 1582

I use it since... a lot of years !!!


Code: Text: [Select]
  1. ' DayAndJulian  by euklides
  2. Datum: INPUT "DATE in form MMDDYYYY or nothing to stop"; k$
  3. IF LEN(k$) <> 8 THEN END
  4. M# = VAL(LEFT$(k$, 2)): J# = VAL(MID$(k$, 3, 2)): A# = VAL(RIGHT$(k$, 4))
  5. IF J# < 1 OR J# > 31 OR M# < 1 OR M# > 12 THEN PRINT " Date not correct":goto Datum
  6. GOSUB GJ
  7. PRINT jour$; M#; "/"; J#; "/"; A#; "/ julian-->"; jj#
  8. PRINT "----------------"
  9. GOTO Datum
  10.  
  11.  
  12. GJ: XXJ# = J#: XXA# = A#: XXM# = M#: J# = J# + .5: C# = 1720994.5#: Y# = INT(A# / 100) - 6: IF M# < 3 THEN A# = A# - 1
  13. M# = M# + 1: IF M# < 4 THEN M# = M# + 12
  14. IF A# > 0 THEN IF M# < 3 THEN A# = A# - 1
  15. jj# = INT(365.25 * A#) + INT(30.6001 * M#) + J# + C# - Y#
  16. IF XXA# > 1999 THEN jj# = jj# + 1
  17. D# = jj# - 2299162#: D# = jj# / 7 - INT(jj# / 7): D# = INT((D# + .01) * 7)
  18. jour$ = "Monday   Tuesday  WednesdayThursday Friday   Saturday Sunday   "
  19. jour$ = RTRIM$(MID$(jour$, D# * 9 + 1, 9)): J# = XXJ#: M# = XXM#: A# = XXA#: RETURN
  20.  
« Last Edit: August 02, 2019, 05:07:30 am by euklides »
Why not yes ?

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: Weekday Finder
« Reply #11 on: August 02, 2019, 05:06:39 am »
Do any of our (presumably) older members remember making a rotating disc version of the Day Calculator?  I did (made out of breakfast cereal packets).  Ah!  Those Were The Days!

Offline Dimster

  • Forum Resident
  • Posts: 500
    • View Profile
Re: Weekday Finder
« Reply #12 on: August 02, 2019, 09:46:11 am »
There is a simple formula for calculating a Leap Year.

IF FullYears MOD 4 = 0 THEN Days = 29

As a Leap Year is every 4 years, if you divide the year by 4 and it comes out as an integer then you will have one extra day in Feb. ie 2019/4 = 504.75, 2020/4= 505, 2021/4 = 505.25  so the year 2020 is a leap year.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Weekday Finder
« Reply #13 on: August 02, 2019, 12:32:53 pm »
That's a neat way to do it euklides!

Dimster, usually yes. But also every 100 years, like 1800 and 1900, it is NOT a Leap Year (not sure why but it's true). BUT if a year is divisible by 400 then it IS a Leap Year, which is why we had a Leap Year in 2000. My Birthday is February 29, so I think all of this is awesome. :)

Marked as best answer by SierraKen on August 03, 2019, 09:53:23 pm

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Weekday Finder
« Reply #14 on: August 04, 2019, 01:53:11 am »
Well, lol, this program turned out to be trash most likely. I was working on a calendar maker all day on Saturday and the evening, almost got it done, when I noticed that something was wrong with May of the year 2020. It kept messing up on me a lot. So after many hours of trying to fix it, I wondered to myself if it was that old equation that this Weekday Finder uses, and yes it is. Both programs can't calculate a month that falls onto 6 weeks, for example, May 2020 starts on a Friday and ends on a Sunday, so it's 6 weeks needed and it just can't handle that. I don't know what the professionals use for their equations to find the days of the week, but I'm giving up on this for now. So, if you have this Weekly Finder, please delete it with my apologies. I guess that serves me right for using stuff I find online that I don't know 100% of.