QB64.org Forum

Active Forums => Programs => Topic started by: SierraKen on August 01, 2019, 11:55:06 pm

Title: Weekday Finder
Post by: SierraKen 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.  
Title: Re: Weekday Finder
Post by: bplus 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! :)
Title: Re: Weekday Finder
Post by: SierraKen 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. :)
Title: Re: Weekday Finder
Post by: bplus 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.
Title: Re: Weekday Finder
Post by: SierraKen 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.  
Title: Re: Weekday Finder
Post by: SierraKen 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.  
Title: Re: Weekday Finder
Post by: SierraKen 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.  

Title: Re: Weekday Finder
Post by: SierraKen 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.  

Title: Re: Weekday Finder
Post by: SierraKen 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.  
Title: Re: Weekday Finder
Post by: Qwerkey 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.


Title: Re: Weekday Finder
Post by: euklides 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.  
Title: Re: Weekday Finder
Post by: Qwerkey 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!
Title: Re: Weekday Finder
Post by: Dimster 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.
Title: Re: Weekday Finder
Post by: SierraKen 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. :)
Title: Re: Weekday Finder
Post by: SierraKen 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.
Title: Re: Weekday Finder
Post by: SMcNeill on August 04, 2019, 02:05:26 am
Code: QB64: [Select]
  1. FUNCTION GetDay$ (mm, dd, yyyy) 'use 4 digit year
  2.     'From Zeller's congruence: https://en.wikipedia.org/wiki/Zeller%27s_congruence
  3.     IF mm < 3 THEN mm = mm + 12: yyyy = yyyy - 1
  4.     century = yyyy MOD 100
  5.     zerocentury = yyyy \ 100
  6.     result = (dd + INT(13 * (mm + 1) / 5) + century + INT(century / 4) + INT(zerocentury / 4) + 5 * zerocentury) MOD 7
  7.     SELECT CASE result
  8.         CASE 0: Day$ = "Saturday"
  9.         CASE 1: Day$ = "Sunday"
  10.         CASE 2: Day$ = "Monday"
  11.         CASE 3: Day$ = "Tuesday"
  12.         CASE 4: Day$ = "Wednesday"
  13.         CASE 5: Day$ = "Thursday"
  14.         CASE 6: Day$ = "Friday"
  15.     END SELECT
Title: Re: Weekday Finder
Post by: euklides on August 04, 2019, 04:12:10 am
My program based on the Julian calendar seems to be better, I think ?
Title: Re: Weekday Finder
Post by: bplus on August 04, 2019, 08:40:53 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.


(Dang! 2 replies I didn't see since this post above and my reply below.)

I don't think the problem you describe is the fault of the formula, it is giving you the proper weekday name isn't it? (I haven't checked.)

Months that span over 6 weeks 4 full + 2 partial are always trouble for calendar makers, who wants to waste all that paper space for 1 or 2 days on each side of the 4 full weeks, yuck.

Here is my attempt and Pete's old code:
https://www.qb64.org/forum/index.php?topic=855.msg100586#msg100586
Title: Re: Weekday Finder
Post by: bplus on August 04, 2019, 09:12:19 am
Code: QB64: [Select]
  1. FUNCTION GetDay$ (mm, dd, yyyy) 'use 4 digit year
  2.     'From Zeller's congruence: https://en.wikipedia.org/wiki/Zeller%27s_congruence
  3.     IF mm < 3 THEN mm = mm + 12: yyyy = yyyy - 1
  4.     century = yyyy MOD 100
  5.     zerocentury = yyyy \ 100
  6.     result = (dd + INT(13 * (mm + 1) / 5) + century + INT(century / 4) + INT(zerocentury / 4) + 5 * zerocentury) MOD 7
  7.     SELECT CASE result
  8.         CASE 0: Day$ = "Saturday"
  9.         CASE 1: Day$ = "Sunday"
  10.         CASE 2: Day$ = "Monday"
  11.         CASE 3: Day$ = "Tuesday"
  12.         CASE 4: Day$ = "Wednesday"
  13.         CASE 5: Day$ = "Thursday"
  14.         CASE 6: Day$ = "Friday"
  15.     END SELECT

OK, fixed
Code: QB64: [Select]
  1. _TITLE "GetDay$ function test."
  2.     PRINT "(don't forget 0's, just enter to quit)"
  3.     INPUT "  Enter yyyy-mm-dd date format: "; yymmdd$
  4.     yyyy = VAL(MID$(yymmdd$, 1, 4))
  5.     mm = VAL(MID$(yymmdd$, 6, 2))
  6.     dd = VAL(MID$(yymmdd$, 9, 2))
  7.     PRINT GetDay$(mm, dd, yyyy)
  8.     PRINT
  9. LOOP UNTIL yymmdd$ = ""
  10.  
  11. 'Steve (SAM) function fix for Ken
  12. FUNCTION GetDay$ (mm, dd, yyyy) 'use 4 digit year
  13.     'From Zeller's congruence: https://en.wikipedia.org/wiki/Zeller%27s_congruence
  14.     IF mm < 3 THEN mm = mm + 12: yyyy = yyyy - 1
  15.     century = yyyy MOD 100
  16.     zerocentury = yyyy \ 100
  17.     result = (dd + INT(13 * (mm + 1) / 5) + century + INT(century / 4) + INT(zerocentury / 4) + 5 * zerocentury) MOD 7
  18.     SELECT CASE result
  19.         CASE 0: Day$ = "Saturday"
  20.         CASE 1: Day$ = "Sunday"
  21.         CASE 2: Day$ = "Monday"
  22.         CASE 3: Day$ = "Tuesday"
  23.         CASE 4: Day$ = "Wednesday"
  24.         CASE 5: Day$ = "Thursday"
  25.         CASE 6: Day$ = "Friday"
  26.     END SELECT
  27.     GetDay$ = Day$
  28.  
Title: Re: Weekday Finder
Post by: bplus on August 04, 2019, 10:24:03 am
Checking KenDay$ and GetDay$ for next 10 Christmas dates, yeah Ken you are a bit off:
Code: QB64: [Select]
  1. _TITLE "Ken Day test" 'B+ started 2019-08-04 Sunday
  2. SCREEN _NEWIMAGE(400, 760, 32)
  3. FOR yyyy = 2019 TO 2029
  4.     'PRINT "(don't forget 0's, just enter to quit)"
  5.     'INPUT "  Enter yyyy-mm-dd date format: "; yymmdd$
  6.     'yyyy = VAL(MID$(yymmdd$, 1, 4))
  7.     'mm = VAL(MID$(yymmdd$, 6, 2))
  8.     'dd = VAL(MID$(yymmdd$, 9, 2))
  9.     PRINT "Christmas"; yyyy
  10.     PRINT "  Ken day = "; kenDay$(12, 25, yyyy)
  11.     PRINT "Steve day = "; GetDay$(12, 25, yyyy)
  12.     PRINT
  13.  
  14. FUNCTION kenDay$ (yyyy, mm, dd)
  15.  
  16.     'Months
  17.     '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.
  18.     mm = mm - 2  ' < edit: still off
  19.     IF mm = 1 THEN mm = 11: yyyy = yyyy - 1
  20.     IF mm = 2 THEN mm = 12: yyyy = yyyy - 1
  21.  
  22.     'Full Year.
  23.     y$ = STR$(yyyy)
  24.  
  25.     'Last 2 digits of year.
  26.     yy$ = RIGHT$(y$, 2)
  27.     yy = VAL(yy$)
  28.  
  29.     'Century
  30.     c$ = LEFT$(y$, 3)
  31.     c = VAL(c$)
  32.  
  33.     'Here is Zeller's Rule equation.
  34.  
  35.     weekday = (dd + INT(((13 * mm) - 1) / 5) + yy + INT(yy / 4) + INT(c / 4) - (2 * c)) MOD 7
  36.  
  37.     IF weekday = 0 THEN w$ = "Sunday"
  38.     IF weekday = 1 THEN w$ = "Monday"
  39.     IF weekday = 2 THEN w$ = "Tuesday"
  40.     IF weekday = 3 THEN w$ = "Wednesday"
  41.     IF weekday = 4 THEN w$ = "Thursday"
  42.     IF weekday = 5 THEN w$ = "Friday"
  43.     IF weekday = 6 THEN w$ = "Saturday"
  44.     kenDay$ = w$
  45.  
  46. 'Steve (SAM) function fix for Ken
  47. FUNCTION GetDay$ (mm, dd, yyyy) 'use 4 digit year
  48.     'From Zeller's congruence: https://en.wikipedia.org/wiki/Zeller%27s_congruence
  49.     IF mm < 3 THEN mm = mm + 12: yyyy = yyyy - 1
  50.     century = yyyy MOD 100
  51.     zerocentury = yyyy \ 100
  52.     result = (dd + INT(13 * (mm + 1) / 5) + century + INT(century / 4) + INT(zerocentury / 4) + 5 * zerocentury) MOD 7
  53.     SELECT CASE result
  54.         CASE 0: Day$ = "Saturday"
  55.         CASE 1: Day$ = "Sunday"
  56.         CASE 2: Day$ = "Monday"
  57.         CASE 3: Day$ = "Tuesday"
  58.         CASE 4: Day$ = "Wednesday"
  59.         CASE 5: Day$ = "Thursday"
  60.         CASE 6: Day$ = "Friday"
  61.     END SELECT
  62.     GetDay$ = Day$
  63.  
  64.  

EDIT: fix line that should of (hee hee) read (mm = mm - 2)

Update: Big screw up with misaligned arguments when testing KenDay$, my apologies. See new test below...
Title: Re: Weekday Finder
Post by: SierraKen on August 04, 2019, 11:28:49 am
Wow so much help and so much to choose from! LOL Plus after I turned off my computer last night I remembered that I should have posted that I will try the one euklides posted. And since I have never used a Function before, I will try both Euk's and B+'s and see which one will work easiest on my program later today. Thanks everyone :))) The one euklides posted works fine for May 2020, I did a quick test on it. Will try B+'s soon..... ahh I see B+ is using the Function as well.
Title: Re: Weekday Finder
Post by: SierraKen on August 04, 2019, 11:58:00 am
Since B+ spent so much time helping me, I'll use his and SmMcNeill's, and try my hands at a Function. :)
Title: Re: Weekday Finder
Post by: bplus on August 04, 2019, 12:22:40 pm
Dang it, I see another screw up I did with testing Ken's function, misaligned arguments, blah! :(

Be right back!

Big apologies to Ken!

Ken, your days for Christmas for 10 years are matching up with Steve's, I screwed up the test by misaligning the arguments to the parameters ie I used the same order of month, day, year as I used in Steve's but I wrote the translation of your code into the Function with y, m, d order.

Here is revised test:
Code: QB64: [Select]
  1. _TITLE "Ken Day test" 'B+ started 2019-08-04 Sunday
  2. SCREEN _NEWIMAGE(400, 760, 32)
  3. FOR yyyy = 2019 TO 2029
  4.     'PRINT "(don't forget 0's, just enter to quit)"
  5.     'INPUT "  Enter yyyy-mm-dd date format: "; yymmdd$
  6.     'yyyy = VAL(MID$(yymmdd$, 1, 4))
  7.     'mm = VAL(MID$(yymmdd$, 6, 2))
  8.     'dd = VAL(MID$(yymmdd$, 9, 2))
  9.     PRINT "Christmas"; yyyy
  10.     PRINT "  Ken day = "; kenDay$(12, 25, yyyy)
  11.     PRINT "Steve day = "; GetDay$(12, 25, yyyy)
  12.     PRINT
  13.  
  14. FUNCTION kenDay$ (m AS INTEGER, d AS INTEGER, y AS INTEGER) ' now same order as GetDay$ function
  15.     mm = m 'get copies so don't change incoming when out going
  16.     dd = d
  17.     yyyy = y
  18.     'Months
  19.     '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.
  20.     mm = mm - 2 ' < edit: still off
  21.     IF mm = 1 THEN mm = 11: yyyy = yyyy - 1
  22.     IF mm = 2 THEN mm = 12: yyyy = yyyy - 1
  23.  
  24.     'Full Year.
  25.     y$ = STR$(yyyy)
  26.  
  27.     'Last 2 digits of year.
  28.     yy$ = RIGHT$(y$, 2)
  29.     yy = VAL(yy$)
  30.  
  31.     'Century
  32.     c$ = LEFT$(y$, 3)
  33.     c = VAL(c$)
  34.  
  35.     'Here is Zeller's Rule equation.
  36.  
  37.     weekday = (dd + INT(((13 * mm) - 1) / 5) + yy + INT(yy / 4) + INT(c / 4) - (2 * c)) MOD 7
  38.  
  39.     IF weekday = 0 THEN w$ = "Sunday"
  40.     IF weekday = 1 THEN w$ = "Monday"
  41.     IF weekday = 2 THEN w$ = "Tuesday"
  42.     IF weekday = 3 THEN w$ = "Wednesday"
  43.     IF weekday = 4 THEN w$ = "Thursday"
  44.     IF weekday = 5 THEN w$ = "Friday"
  45.     IF weekday = 6 THEN w$ = "Saturday"
  46.     kenDay$ = w$
  47.  
  48. 'Steve (SAM) function fix for Ken
  49. FUNCTION GetDay$ (mm, dd, yyyy) 'use 4 digit year
  50.     'From Zeller's congruence: https://en.wikipedia.org/wiki/Zeller%27s_congruence
  51.     IF mm < 3 THEN mm = mm + 12: yyyy = yyyy - 1
  52.     century = yyyy MOD 100
  53.     zerocentury = yyyy \ 100
  54.     result = (dd + INT(13 * (mm + 1) / 5) + century + INT(century / 4) + INT(zerocentury / 4) + 5 * zerocentury) MOD 7
  55.     SELECT CASE result
  56.         CASE 0: Day$ = "Saturday"
  57.         CASE 1: Day$ = "Sunday"
  58.         CASE 2: Day$ = "Monday"
  59.         CASE 3: Day$ = "Tuesday"
  60.         CASE 4: Day$ = "Wednesday"
  61.         CASE 5: Day$ = "Thursday"
  62.         CASE 6: Day$ = "Friday"
  63.     END SELECT
  64.     GetDay$ = Day$
  65.  
Title: Re: Weekday Finder
Post by: SierraKen on August 04, 2019, 12:23:36 pm
Awesome I fixed it!!! Thanks guys!!! Instead of a Function I turned it into a SUB because all I needed was variables and strings. I'm almost done now with my Calendar Maker. I just have to adjust some things first, hopefully will be done today and I'll make a new forum topic for it. It will have all U.S. Federal Holidays as well, which I already added. Plus it will give the user the ability to save it as a JPG and also print it on the printer. The funny thing is, I'm still getting used to the printer and I accidentally (again) printed a whole sheet of black. lol So thankfully QB64 has the ability to save the screen and that's what I'm going to do, and then print it after loading the JPG. Oh, and it only makes 1 month at a time.
Title: Re: Weekday Finder
Post by: SierraKen on August 04, 2019, 12:26:35 pm
Oh Wow B+... I'll have to see it later on, I have to get going for a few hours. I might have fixed it myself, I messed around with it a little bit to make the SUB and also use Y instead of YYYY and weekday instead of that other one you had for each weekday number. See you later today, thanks again for the help!
Title: Re: Weekday Finder
Post by: SierraKen on August 04, 2019, 12:28:35 pm
Oh, and since you are probably curious, this is what I have so far for the Calendar Maker... it's VERY VERY VERY rough so far, and NOT finished, but getting closer. :)

Code: QB64: [Select]
  1.  
  2. 'Something is wrong with weekday variable, it goes into the negative when 6 "weeks" are needed on the loop.
  3.  
  4.  
  5. _TITLE "Calendar Maker"
  6. start:
  7. dd = 0
  8. leap = 0
  9. SCREEN _NEWIMAGE(800, 600, 32)
  10. PRINT "                       Monthly Calendar Maker"
  11. PRINT "                           By Ken G."
  12. PRINT "This program will make a calendar for the year and month you want."
  13. PRINT "It will also name the U.S. Federal Holidays on their days."
  14. INPUT "Type the year here: ", y
  15. again2:
  16. INPUT "Type the month here: ", m
  17. IF m < 1 OR m > 12 THEN PRINT "1-12 only, try again.": GOTO again2:
  18.  
  19. IF m = 1 THEN month$ = " January"
  20. IF m = 2 THEN month$ = "February"
  21. IF m = 3 THEN month$ = "  March"
  22. IF m = 4 THEN month$ = "  April"
  23. IF m = 5 THEN month$ = "  May"
  24. IF m = 6 THEN month$ = "  June"
  25. IF m = 7 THEN month$ = "  July"
  26. IF m = 8 THEN month$ = " August"
  27. IF m = 9 THEN month$ = "September"
  28. IF m = 10 THEN month$ = " October"
  29. IF m = 11 THEN month$ = "November"
  30. IF m = 12 THEN month$ = "December"
  31.  
  32. IF m <> 2 THEN GOTO nex:
  33. 'Calculate to see if it's a Leap Year.
  34. IF y / 400 = INT(y / 400) THEN leap = 1: GOTO more:
  35. IF y / 4 = INT(y / 4) THEN leap = 1
  36. IF y / 100 = INT(y / 100) THEN leap = 0
  37. more:
  38. IF leap = 1 THEN days = 29
  39. IF leap = 0 THEN days = 28
  40. GOTO weekday:
  41. nex:
  42. IF m = 1 THEN days = 31
  43. IF m = 3 THEN days = 31
  44. IF m = 4 THEN days = 30
  45. IF m = 5 THEN days = 31
  46. IF m = 6 THEN days = 30
  47. IF m = 7 THEN days = 31
  48. IF m = 8 THEN days = 31
  49. IF m = 9 THEN days = 30
  50. IF m = 10 THEN days = 31
  51. IF m = 11 THEN days = 30
  52. IF m = 12 THEN days = 31
  53. weekday:
  54. k = 1
  55. mm = m
  56. yy = y
  57. GetDay mm, dd, y, weekday
  58.  
  59. 'This section makes the calendar.
  60. make:
  61. LINE (0, 0)-(800, 600), _RGB32(255, 255, 255), BF
  62. COLOR _RGB(0, 0, 0), _RGB(255, 255, 255)
  63. LOCATE 1, 47: PRINT month$
  64. LOCATE 2, 48: PRINT yy
  65.  
  66. FOR x = 20 TO 780 STEP 108
  67.     LINE (x, 100)-(x, 580), _RGB32(0, 0, 0)
  68. FOR z = 100 TO 580 STEP 80
  69.     LINE (16, z)-(780, z), _RGB32(0, 0, 0)
  70.  
  71. LOCATE 5, 8: PRINT "SUNDAY"
  72. LOCATE 5, 21: PRINT "MONDAY"
  73. LOCATE 5, 34: PRINT "TUESDAY"
  74. LOCATE 5, 47: PRINT "WEDNESDAY"
  75. LOCATE 5, 60: PRINT "THURSDAY"
  76. LOCATE 5, 75: PRINT "FRIDAY"
  77. LOCATE 5, 87: PRINT "SATURDAY"
  78. w = (weekday * 13) + 8
  79. FOR week = 8 TO 59 STEP 5
  80.     FOR day = w TO 91 STEP 13
  81.         dd = dd + 1
  82.         k = dd
  83.         GetDay mm, dd, y, weekday
  84.         IF weekday < 4 THEN LOCATE week, day - 1: PRINT dd
  85.         IF weekday >= 4 THEN LOCATE week, day + 1: PRINT dd
  86.         IF m = 1 AND dd = 1 THEN LOCATE week + 2, day - 1: PRINT "New Years"
  87.         IF m = 1 AND weekday = 1 AND dd > 16 AND dd < 24 THEN LOCATE week + 4, day - 1: PRINT "MLK Jr. Day"
  88.         IF m = 2 AND weekday = 1 AND dd > 16 AND dd < 24 THEN LOCATE week + 4, day - 1: PRINT "Pres. Day"
  89.         IF m = 5 AND weekday = 1 AND dd > 24 THEN LOCATE week + 4, day - 1: PRINT "Mem. Day"
  90.         IF m = 7 AND dd = 4 THEN LOCATE week + 4, day - 1: PRINT "Independence"
  91.         IF m = 9 AND weekday = 1 AND dd < 8 THEN LOCATE week + 2, day - 1: PRINT "Labor Day"
  92.         IF m = 10 AND dd > 9 AND dd < 16 AND weekday = 1 THEN LOCATE week + 4, day - 1: PRINT "Columbus"
  93.         IF m = 11 AND dd = 11 THEN LOCATE week + 4, day - 1: PRINT "Veterans Day"
  94.         IF m = 11 AND dd > 21 AND dd < 29 AND weekday = 5 THEN LOCATE week + 4, day - 1: PRINT "Thanksgving"
  95.         IF m = 12 AND dd = 25 THEN LOCATE week + 4, day - 1: PRINT "Christmas"
  96.         IF dd = days THEN GOTO more2:
  97.     NEXT day
  98.     w = 7
  99. NEXT week
  100.  
  101.  
  102. more2:
  103. LOCATE 29, 1: INPUT "Press Enter to go back to menu.", a$
  104. GOTO start:
  105.  
  106.  
  107.  
  108.  
  109.  
  110. 'This section saves the calendar to a JPG file.
  111.  
  112. SaveImage 0, "screenshot" 'saves entire program screen as "screenshot.bmp"
  113.  
  114. weekdays:
  115. 'DO
  116. '    PRINT "(don't forget 0's, just enter to quit)"
  117. 'INPUT "  Enter yyyy-mm-dd date format: "; yymmdd$
  118. 'yyyy = VAL(MID$(yymmdd$, 1, 4))
  119. 'mm = VAL(MID$(yymmdd$, 6, 2))
  120. 'dd = VAL(MID$(yymmdd$, 9, 2))
  121. 'PRINT GetDay$(mm, dd, yyyy)
  122. 'PRINT
  123. 'LOOP UNTIL yymmdd$ = ""
  124. 'RETURN
  125.  
  126. 'Steve (SAM) function fix for Ken
  127. SUB GetDay (mm, dd, y, weekday) 'use 4 digit year
  128.     'From Zeller's congruence: https://en.wikipedia.org/wiki/Zeller%27s_congruence
  129.     IF mm < 3 THEN mm = mm + 12: y = y - 1
  130.     century = y MOD 100
  131.     zerocentury = y \ 100
  132.     weekday = (dd + INT(13 * (mm + 1) / 5) + century + INT(century / 4) + INT(zerocentury / 4) + 5 * zerocentury) MOD 7
  133.     SELECT CASE weekday
  134.         CASE 0: Day$ = "Saturday"
  135.         CASE 1: Day$ = "Sunday"
  136.         CASE 2: Day$ = "Monday"
  137.         CASE 3: Day$ = "Tuesday"
  138.         CASE 4: Day$ = "Wednesday"
  139.         CASE 5: Day$ = "Thursday"
  140.         CASE 6: Day$ = "Friday"
  141.     END SELECT
  142.  
  143.  
  144.  
  145.  
  146. SUB SaveImage (image AS LONG, filename AS STRING)
  147.     bytesperpixel& = _PIXELSIZE(image&)
  148.     IF bytesperpixel& = 0 THEN PRINT "Text modes unsupported!": END
  149.     IF bytesperpixel& = 1 THEN bpp& = 8 ELSE bpp& = 24
  150.     x& = _WIDTH(image&)
  151.     y& = _HEIGHT(image&)
  152.     b$ = "BM????QB64????" + MKL$(40) + MKL$(x&) + MKL$(y&) + MKI$(1) + MKI$(bpp&) + MKL$(0) + "????" + STRING$(16, 0) 'partial BMP header info(???? to be filled later)
  153.     IF bytesperpixel& = 1 THEN
  154.         FOR c& = 0 TO 255 ' read BGR color settings from JPG image + 1 byte spacer(CHR$(0))
  155.             cv& = _PALETTECOLOR(c&, image&) ' color attribute to read.
  156.             b$ = b$ + CHR$(_BLUE32(cv&)) + CHR$(_GREEN32(cv&)) + CHR$(_RED32(cv&)) + CHR$(0) 'spacer byte
  157.         NEXT
  158.     END IF
  159.     MID$(b$, 11, 4) = MKL$(LEN(b$)) ' image pixel data offset(BMP header)
  160.     lastsource& = _SOURCE
  161.     _SOURCE image&
  162.     IF ((x& * 3) MOD 4) THEN padder$ = STRING$(4 - ((x& * 3) MOD 4), 0)
  163.     FOR py& = y& - 1 TO 0 STEP -1 ' read JPG image pixel color data
  164.         r$ = ""
  165.         FOR px& = 0 TO x& - 1
  166.             c& = POINT(px&, py&) 'POINT 32 bit values are large LONG values
  167.             IF bytesperpixel& = 1 THEN r$ = r$ + CHR$(c&) ELSE r$ = r$ + LEFT$(MKL$(c&), 3)
  168.         NEXT px&
  169.         d$ = d$ + r$ + padder$
  170.     NEXT py&
  171.     _SOURCE lastsource&
  172.     MID$(b$, 35, 4) = MKL$(LEN(d$)) ' image size(BMP header)
  173.     b$ = b$ + d$ ' total file data bytes to create file
  174.     MID$(b$, 3, 4) = MKL$(LEN(b$)) ' size of data file(BMP header)
  175.     IF LCASE$(RIGHT$(filename$, 4)) <> ".jpg" THEN ext$ = ".jpg"
  176.     f& = FREEFILE
  177.     OPEN filename$ + ext$ FOR OUTPUT AS #f&: CLOSE #f& ' erases an existing file
  178.     OPEN filename$ + ext$ FOR BINARY AS #f&
  179.     PUT #f&, , b$
  180.     CLOSE #f&
  181.  
Title: Re: Weekday Finder
Post by: bplus on August 04, 2019, 08:22:28 pm
Hi Ken,

I have tested more dates with code in reply #19, though it gets Christmas correct for next 10 years, it misses with March 2019 dates.

The calendars for 2019 all do seem to start and end on correct day. You might control labels better with _PRINTSTRING which locates to the pixel instead of character cell rows and columns, start text just below and right of top left line intersects.
Title: Re: Weekday Finder
Post by: SierraKen on August 05, 2019, 01:41:25 am
Thanks B+, I'm 99.9% sure that I'm finished with the Calendar Maker. I'm starting a new forum topic now only for that program.