Author Topic: How to calculate the day of the week for 40 years into the future  (Read 5098 times)

0 Members and 1 Guest are viewing this topic.

Offline rcamp48

  • Newbie
  • Posts: 62
    • View Profile
As many of you may know, I have written both a Lotto 649 and a Lotto Max program. One of the things I wanted to do was to automatically enter the next draw date for the next 40 years into the future. Now that poses a unique problem, not only have you got leap years , different month lengths, and 2 draws a week, in Lotto 649 its on Wednesdays and Fridays. In Lotto Max , up until the 17th of May 2019, it was one draw a week with 7 numbers and a bonus number , but after that it changed to 2 draws a week with 50 numbers instead of 49.  Quite a problem, both programs are sorta finished, the Lotto Max program needs the data for the day of the week after the last month. What I am showing you is how I got around all of that. A lot of if then statements, but does anyone know of a mathematical formula that will take into account 2 draws, one on Tuesday, and the other on Friday? Oh did I tell you that you also have to adjust for the 28-29-30-31 day months and figure out what day the draw falls on with each month?

Here is an idea of how I did it, the program sample is long, as there is 40 years of data for each month. See for yourself.

calculatedayofweek:

'Find Day of the Week

n = 0: n1 = 0: n2 = 0: n3 = 0: n4 = 0
n1 = FIX(3 * (m + 1) / 5)
n2 = FIX(y / 4)
n3 = FIX(y / 100)
n4 = FIX(y / 400)


n = dy + (2 * m) + n1 + y + n2 - n3 + n4 + 2

day1 = n MOD 7
IF dayflag = 0 THEN
END IF
RETURN
add3or4days:
dayflag = 1
GOSUB rollover
RETURN

rollover:
dayflag = 0
GOSUB calculatedayofweek
GOSUB rollover2
IF day1 = 6 AND count = 0 THEN
    IF rollover = 0 THEN
        adddays = 4
        dy = dy + adddays
    ELSEIF rollover = 1 THEN
        adddays = 4
        dy = dy + adddays + adjust
    END IF
ELSEIF day1 = 5 AND count = 0 THEN
    IF rollover = 0 THEN
        adddays = 4
        dy = dy + adddays
    ELSEIF rollover = 1 THEN
        adddays = 4
        dy = dy + adddays + adjust
    END IF
ELSEIF day1 = 4 AND count = 0 THEN
    IF rollover = 0 THEN
        adddays = 3
        dy = dy + adddays
    ELSEIF rollover = 1 THEN
        adddays = 3
        dy = dy + adddays + adjust
    END IF

ELSEIF day1 = 4 AND count = 0 THEN
    IF rollover = 0 THEN
        adddays = 3
        dy = dy + adddays
    ELSEIF rollover = 1 THEN
        adddays = 3
        dy = dy + adddays + adjust
    END IF
ELSEIF day1 = 3 AND count = 0 THEN
    IF rollover = 0 THEN
        adddays = 3
        dy = dy + adddays
    ELSEIF rollover = 1 THEN
        adddays = 3
        dy = dy + adddays + adjust
    END IF
ELSEIF day1 = 2 AND count = 0 THEN
    IF rollover = 0 THEN
        adddays = 3
        dy = dy + adddays
    ELSEIF rollover = 1 THEN
        adddays = 3
        dy = dy + adddays + adjust
    END IF
ELSEIF day1 = 1 AND count = 0 THEN
    IF rollover = 0 THEN
        adddays = 3
        dy = dy + adddays
    ELSEIF rollover = 1 THEN
        adddays = 3
        dy = dy + adddays + adjust
    END IF
ELSEIF day1 = 0 AND count = 0 THEN
    IF rollover = 0 THEN
        adddays = 3
        dy = dy + adddays
    ELSEIF rollover = 1 THEN
        adddays = 3
        dy = dy + adddays + adjust
    END IF
END IF
IF adddays = 4 THEN day8 = 3
IF adddays = 3 THEN day8 = 6
adjust = 0
dayflag = 1

GOSUB calculatedayofweek

rollover2:
IF y = 2019 THEN
    IF dy > 31 AND m = 1 THEN m = 2: dy = 2: rollover = 1: adjust = 0
    IF dy > 28 AND m = 2 THEN m = 3: dy = 2: rollover = 1: adjust = 3
    IF dy > 31 AND m = 3 THEN m = 4: dy = 3: rollover = 1: adjust = 0
    IF dy > 30 AND m = 4 THEN m = 5: dy = 1: rollover = 1: adjust = 1
    IF dy > 31 AND m = 5 THEN m = 6: dy = 1: rollover = 1: adjust = 0
    IF dy > 30 AND m = 6 THEN m = 7: dy = 2: rollover = 1: adjust = 1
    IF dy > 31 AND m = 7 THEN m = 8: dy = 2: rollover = 1: adjust = 0
    IF dy > 31 AND m = 8 THEN m = 9: dy = 3: rollover = 1: adjust = 0
    IF dy > 30 AND m = 9 THEN m = 10: dy = 1: rollover = 1: adjust = 1
    IF dy > 31 AND m = 10 THEN m = 11: dy = 1: rollover = 1: adjust = 0
    IF dy > 30 AND m = 11 THEN m = 12: dy = 3: rollover = 1: adjust = 1
    IF dy > 31 AND m = 12 THEN y = 2020: m = 1: dy = 3: rollover = 1: adjust = 0
END IF
IF y = 2020 THEN
    IF dy > 31 AND m = 1 THEN m = 2: dy = 4: rollover = 1: adjust = 0
    IF dy > 29 AND m = 2 THEN m = 3: dy = 3: rollover = 1: adjust = 2
    IF dy > 31 AND m = 3 THEN m = 4: dy = 3: rollover = 1: adjust = 0
    IF dy > 30 AND m = 4 THEN m = 5: dy = 1: rollover = 1: adjust = 1
    IF dy > 31 AND m = 5 THEN m = 6: dy = 2: rollover = 1: adjust = 0
    IF dy > 30 AND m = 6 THEN m = 7: dy = 2: rollover = 1: adjust = 1
    IF dy > 31 AND m = 7 THEN m = 8: dy = 3: rollover = 1: adjust = 0
    IF dy > 31 AND m = 8 THEN m = 9: dy = 4: rollover = 1: adjust = 0
    IF dy > 30 AND m = 9 THEN m = 10: dy = 3: rollover = 1: adjust = 1
    IF dy > 31 AND m = 10 THEN m = 11: dy = 1: rollover = 1: adjust = 0
    IF dy > 30 AND m = 11 THEN m = 12: dy = 1: rollover = 1: adjust = 1
    IF dy > 31 AND m = 12 THEN y = 2021: m = 1: dy = 1: rollover = 1: adjust = 0
END IF
IF y = 2021 THEN
    IF dy > 31 AND m = 1 THEN m = 2: dy = 2: rollover = 1: adjust = 0
    IF dy > 28 AND m = 2 THEN m = 3: dy = 2: rollover = 1: adjust = 3
    IF dy > 31 AND m = 3 THEN m = 4: dy = 2: rollover = 1: adjust = 0
    IF dy > 30 AND m = 4 THEN m = 5: dy = 4: rollover = 1: adjust = 1
    IF dy > 31 AND m = 5 THEN m = 6: dy = 1: rollover = 1: adjust = 0
    IF dy > 30 AND m = 6 THEN m = 7: dy = 2: rollover = 1: adjust = 1
    IF dy > 31 AND m = 7 THEN m = 8: dy = 3: rollover = 1: adjust = 0
    IF dy > 31 AND m = 8 THEN m = 9: dy = 3: rollover = 1: adjust = 0
    IF dy > 30 AND m = 9 THEN m = 10: dy = 1: rollover = 1: adjust = 1
    IF dy > 31 AND m = 10 THEN m = 11: dy = 2: rollover = 1: adjust = 0
    IF dy > 30 AND m = 11 THEN m = 12: dy = 3: rollover = 1: adjust = 1
    IF dy > 31 AND m = 12 THEN y = 2022: m = 1: dy = 4: rollover = 1: adjust = 0
END IF
IF y = 2022 THEN
    IF dy > 31 AND m = 1 THEN m = 2: dy = 2: rollover = 1: adjust = 0
    IF dy > 28 AND m = 2 THEN m = 3: dy = 2: rollover = 1: adjust = 3
    IF dy > 31 AND m = 3 THEN m = 4: dy = 2: rollover = 1: adjust = 0
    IF dy > 30 AND m = 4 THEN m = 5: dy = 4: rollover = 1: adjust = 1
    IF dy > 31 AND m = 5 THEN m = 6: dy = 1: rollover = 1: adjust = 0
    IF dy > 30 AND m = 6 THEN m = 7: dy = 2: rollover = 1: adjust = 1
    IF dy > 31 AND m = 7 THEN m = 8: dy = 3: rollover = 1: adjust = 0
    IF dy > 31 AND m = 8 THEN m = 9: dy = 3: rollover = 1: adjust = 0
    IF dy > 30 AND m = 9 THEN m = 10: dy = 1: rollover = 1: adjust = 1
    IF dy > 31 AND m = 10 THEN m = 11: dy = 2: rollover = 1: adjust = 0
    IF dy > 30 AND m = 11 THEN m = 12: dy = 3: rollover = 1: adjust = 1
    IF dy > 31 AND m = 12 THEN y = 2023: m = 1: dy = 4: rollover = 1: adjust = 0
END IF
IF y = 2023 THEN
    IF dy > 31 AND m = 1 THEN m = 2: dy = 1: rollover = 1: adjust = 0
    IF dy > 28 AND m = 2 THEN m = 3: dy = 1: rollover = 1: adjust = 3
    IF dy > 31 AND m = 3 THEN m = 4: dy = 1: rollover = 1: adjust = 0
    IF dy > 30 AND m = 4 THEN m = 5: dy = 3: rollover = 1: adjust = 1
    IF dy > 31 AND m = 5 THEN m = 6: dy = 3: rollover = 1: adjust = 0
    IF dy > 30 AND m = 6 THEN m = 7: dy = 1: rollover = 1: adjust = 1
    IF dy > 31 AND m = 7 THEN m = 8: dy = 2: rollover = 1: adjust = 0
    IF dy > 31 AND m = 8 THEN m = 9: dy = 2: rollover = 1: adjust = 0
    IF dy > 30 AND m = 9 THEN m = 10: dy = 4: rollover = 1: adjust = 1
    IF dy > 31 AND m = 10 THEN m = 11: dy = 1: rollover = 1: adjust = 0
    IF dy > 30 AND m = 11 THEN m = 12: dy = 2: rollover = 1: adjust = 1
    IF dy > 31 AND m = 12 THEN y = 2024: m = 1: dy = 3: rollover = 1: adjust = 0
END IF
IF y = 2024 THEN
    IF dy > 31 AND m = 1 THEN m = 2: dy = 3: rollover = 1: adjust = 0
    IF dy > 29 AND m = 2 THEN m = 3: dy = 2: rollover = 1: adjust = 2
    IF dy > 31 AND m = 3 THEN m = 4: dy = 3: rollover = 1: adjust = 0
    IF dy > 30 AND m = 4 THEN m = 5: dy = 1: rollover = 1: adjust = 1
    IF dy > 31 AND m = 5 THEN m = 6: dy = 1: rollover = 1: adjust = 0
    IF dy > 30 AND m = 6 THEN m = 7: dy = 3: rollover = 1: adjust = 1
    IF dy > 31 AND m = 7 THEN m = 8: dy = 3: rollover = 1: adjust = 0
    IF dy > 31 AND m = 8 THEN m = 9: dy = 4: rollover = 1: adjust = 0
    IF dy > 30 AND m = 9 THEN m = 10: dy = 2: rollover = 1: adjust = 1
    IF dy > 31 AND m = 10 THEN m = 11: dy = 2: rollover = 1: adjust = 0
    IF dy > 30 AND m = 11 THEN m = 12: dy = 4: rollover = 1: adjust = 1
    IF dy > 31 AND m = 12 THEN y = 2025: m = 1: dy = 1: rollover = 1: adjust = 0
END IF
IF y = 2025 THEN
    IF dy > 31 AND m = 1 THEN m = 2: dy = 1: rollover = 1: adjust = 0
    IF dy > 28 AND m = 2 THEN m = 3: dy = 1: rollover = 1: adjust = 3
    IF dy > 31 AND m = 3 THEN m = 4: dy = 2: rollover = 1: adjust = 0
    IF dy > 30 AND m = 4 THEN m = 5: dy = 3: rollover = 1: adjust = 1
    IF dy > 31 AND m = 5 THEN m = 6: dy = 4: rollover = 1: adjust = 0
    IF dy > 30 AND m = 6 THEN m = 7: dy = 2: rollover = 1: adjust = 1
    IF dy > 31 AND m = 7 THEN m = 8: dy = 2: rollover = 1: adjust = 0
    IF dy > 31 AND m = 8 THEN m = 9: dy = 3: rollover = 1: adjust = 0
    IF dy > 30 AND m = 9 THEN m = 10: dy = 1: rollover = 1: adjust = 1
    IF dy > 31 AND m = 10 THEN m = 11: dy = 1: rollover = 1: adjust = 0
    IF dy > 30 AND m = 11 THEN m = 12: dy = 3: rollover = 1: adjust = 1
    IF dy > 31 AND m = 12 THEN y = 2026: m = 1: dy = 3: rollover = 1: adjust = 0
END IF
IF y = 2026 THEN
    IF dy > 31 AND m = 1 THEN m = 2: dy = 4: rollover = 1: adjust = 0
    IF dy > 28 AND m = 2 THEN m = 3: dy = 4: rollover = 1: adjust = 3
    IF dy > 31 AND m = 3 THEN m = 4: dy = 1: rollover = 1: adjust = 0
    IF dy > 30 AND m = 4 THEN m = 5: dy = 2: rollover = 1: adjust = 1
    IF dy > 31 AND m = 5 THEN m = 6: dy = 3: rollover = 1: adjust = 0
    IF dy > 30 AND m = 6 THEN m = 7: dy = 1: rollover = 1: adjust = 1
    IF dy > 31 AND m = 7 THEN m = 8: dy = 1: rollover = 1: adjust = 0
    IF dy > 31 AND m = 8 THEN m = 9: dy = 2: rollover = 1: adjust = 0
    IF dy > 30 AND m = 9 THEN m = 10: dy = 3: rollover = 1: adjust = 1
    IF dy > 31 AND m = 10 THEN m = 11: dy = 4: rollover = 1: adjust = 0
    IF dy > 30 AND m = 11 THEN m = 12: dy = 2: rollover = 1: adjust = 1
    IF dy > 31 AND m = 12 THEN y = 2027: m = 1: dy = 3: rollover = 1: adjust = 0
END IF
IF y = 2027 THEN
    IF dy > 31 AND m = 1 THEN m = 2: dy = 3: rollover = 1: adjust = 0
    IF dy > 28 AND m = 2 THEN m = 3: dy = 3: rollover = 1: adjust = 3
    IF dy > 31 AND m = 3 THEN m = 4: dy = 3: rollover = 1: adjust = 0
    IF dy > 30 AND m = 4 THEN m = 5: dy = 1: rollover = 1: adjust = 1
    IF dy > 31 AND m = 5 THEN m = 6: dy = 2: rollover = 1: adjust = 0
    IF dy > 30 AND m = 6 THEN m = 7: dy = 3: rollover = 1: adjust = 1
    IF dy > 31 AND m = 7 THEN m = 8: dy = 4: rollover = 1: adjust = 0
    IF dy > 31 AND m = 8 THEN m = 9: dy = 1: rollover = 1: adjust = 0
    IF dy > 30 AND m = 9 THEN m = 10: dy = 2: rollover = 1: adjust = 1
    IF dy > 31 AND m = 10 THEN m = 11: dy = 3: rollover = 1: adjust = 0
    IF dy > 30 AND m = 11 THEN m = 12: dy = 1: rollover = 1: adjust = 1
    IF dy > 31 AND m = 12 THEN y = 2028: m = 1: dy = 1: rollover = 1: adjust = 0
END IF
IF y = 2028 THEN
    IF dy > 31 AND m = 1 THEN m = 2: dy = 2: rollover = 1: adjust = 0
    IF dy > 29 AND m = 2 THEN m = 3: dy = 1: rollover = 1: adjust = 2
    IF dy > 31 AND m = 3 THEN m = 4: dy = 1: rollover = 1: adjust = 0
    IF dy > 30 AND m = 4 THEN m = 5: dy = 3: rollover = 1: adjust = 1
    IF dy > 31 AND m = 5 THEN m = 6: dy = 3: rollover = 1: adjust = 0
    IF dy > 30 AND m = 6 THEN m = 7: dy = 1: rollover = 1: adjust = 1
    IF dy > 31 AND m = 7 THEN m = 8: dy = 2: rollover = 1: adjust = 0
    IF dy > 31 AND m = 8 THEN m = 9: dy = 2: rollover = 1: adjust = 0
    IF dy > 30 AND m = 9 THEN m = 10: dy = 2: rollover = 1: adjust = 1
    IF dy > 31 AND m = 10 THEN m = 11: dy = 4: rollover = 1: adjust = 0
    IF dy > 30 AND m = 11 THEN m = 12: dy = 1: rollover = 1: adjust = 1
    IF dy > 31 AND m = 12 THEN y = 2029: m = 2: dy = 3: rollover = 1: adjust = 0
END IF
IF y = 2029 THEN
    IF dy > 31 AND m = 1 THEN m = 2: dy = 3: rollover = 1: adjust = 0
    IF dy > 28 AND m = 2 THEN m = 3: dy = 3: rollover = 1: adjust = 3
    IF dy > 31 AND m = 3 THEN m = 4: dy = 4: rollover = 1: adjust = 0
    IF dy > 30 AND m = 4 THEN m = 5: dy = 2: rollover = 1: adjust = 1
    IF dy > 31 AND m = 5 THEN m = 6: dy = 2: rollover = 1: adjust = 0
    IF dy > 30 AND m = 6 THEN m = 7: dy = 2: rollover = 1: adjust = 1
    IF dy > 31 AND m = 7 THEN m = 8: dy = 4: rollover = 1: adjust = 0
    IF dy > 31 AND m = 8 THEN m = 9: dy = 1: rollover = 1: adjust = 0
    IF dy > 30 AND m = 9 THEN m = 10: dy = 3: rollover = 1: adjust = 1
    IF dy > 31 AND m = 10 THEN m = 11: dy = 3: rollover = 1: adjust = 0
    IF dy > 30 AND m = 11 THEN m = 12: dy = 1: rollover = 1: adjust = 1
    IF dy > 31 AND m = 12 THEN y = 2030: m = 1: dy = 2: rollover = 1: adjust = 0
END IF
IF y = 2030 THEN
    IF dy > 31 AND m = 1 THEN m = 2: dy = 2: rollover = 1: adjust = 0
    IF dy > 28 AND m = 2 THEN m = 3: dy = 2: rollover = 1: adjust = 3
    IF dy > 31 AND m = 3 THEN m = 4: dy = 3: rollover = 1: adjust = 0
    IF dy > 30 AND m = 4 THEN m = 5: dy = 1: rollover = 1: adjust = 1
    IF dy > 31 AND m = 5 THEN m = 6: dy = 1: rollover = 1: adjust = 0
    IF dy > 30 AND m = 6 THEN m = 7: dy = 3: rollover = 1: adjust = 1
    IF dy > 31 AND m = 7 THEN m = 8: dy = 3: rollover = 1: adjust = 0
    IF dy > 31 AND m = 8 THEN m = 9: dy = 4: rollover = 1: adjust = 0
    IF dy > 30 AND m = 9 THEN m = 10: dy = 2: rollover = 1: adjust = 1
    IF dy > 31 AND m = 10 THEN m = 11: dy = 2: rollover = 1: adjust = 0
    IF dy > 30 AND m = 11 THEN m = 12: dy = 4: rollover = 1: adjust = 1
    IF dy > 31 AND m = 12 THEN y = 2031: m = 1: dy = 1: rollover = 1: adjust = 0
END IF
IF y = 2031 THEN
    IF dy > 31 AND m = 1 THEN m = 2: dy = 1: rollover = 1: adjust = 0
    IF dy > 28 AND m = 2 THEN m = 3: dy = 1: rollover = 1: adjust = 3
    IF dy > 31 AND m = 3 THEN m = 4: dy = 2: rollover = 1: adjust = 0
    IF dy > 30 AND m = 4 THEN m = 5: dy = 3: rollover = 1: adjust = 1
    IF dy > 31 AND m = 5 THEN m = 6: dy = 4: rollover = 1: adjust = 0
    IF dy > 30 AND m = 6 THEN m = 7: dy = 2: rollover = 1: adjust = 1
    IF dy > 31 AND m = 7 THEN m = 8: dy = 2: rollover = 1: adjust = 0
    IF dy > 31 AND m = 8 THEN m = 9: dy = 3: rollover = 1: adjust = 0
    IF dy > 30 AND m = 9 THEN m = 10: dy = 1: rollover = 1: adjust = 1
    IF dy > 31 AND m = 10 THEN m = 11: dy = 1: rollover = 1: adjust = 0
    IF dy > 30 AND m = 11 THEN m = 12: dy = 3: rollover = 1: adjust = 1
    IF dy > 31 AND m = 12 THEN y = 2032: m = 1: dy = 3: rollover = 1: adjust = 0
END IF
IF y = 2032 THEN
    IF dy > 31 AND m = 1 THEN m = 2: dy = 4: rollover = 1: adjust = 0
    IF dy > 29 AND m = 2 THEN m = 3: dy = 3: rollover = 1: adjust = 2
    IF dy > 31 AND m = 3 THEN m = 4: dy = 4: rollover = 1: adjust = 0
    IF dy > 30 AND m = 4 THEN m = 5: dy = 1: rollover = 1: adjust = 1
    IF dy > 31 AND m = 5 THEN m = 6: dy = 2: rollover = 1: adjust = 0
    IF dy > 30 AND m = 6 THEN m = 7: dy = 3: rollover = 1: adjust = 1
    IF dy > 31 AND m = 7 THEN m = 8: dy = 4: rollover = 1: adjust = 0
    IF dy > 31 AND m = 8 THEN m = 9: dy = 1: rollover = 1: adjust = 0
    IF dy > 30 AND m = 9 THEN m = 10: dy = 2: rollover = 1: adjust = 1
    IF dy > 31 AND m = 10 THEN m = 11: dy = 3: rollover = 1: adjust = 0
    IF dy > 30 AND m = 11 THEN m = 12: dy = 1: rollover = 1: adjust = 1
    IF dy > 31 AND m = 12 THEN y = 2033: m = 1: dy = 1: rollover = 1: adjust = 0
END IF
IF y = 2033 THEN
    IF dy > 31 AND m = 1 THEN m = 2: dy = 2: rollover = 1: adjust = 0
    IF dy > 28 AND m = 2 THEN m = 3: dy = 2: rollover = 1: adjust = 3
    IF dy > 31 AND m = 3 THEN m = 4: dy = 2: rollover = 1: adjust = 0
    IF dy > 30 AND m = 4 THEN m = 5: dy = 4: rollover = 1: adjust = 1
    IF dy > 31 AND m = 5 THEN m = 6: dy = 1: rollover = 1: adjust = 0
    IF dy > 30 AND m = 6 THEN m = 7: dy = 2: rollover = 1: adjust = 1
    IF dy > 31 AND m = 7 THEN m = 8: dy = 3: rollover = 1: adjust = 0
    IF dy > 31 AND m = 8 THEN m = 9: dy = 3: rollover = 1: adjust = 0
    IF dy > 30 AND m = 9 THEN m = 10: dy = 1: rollover = 1: adjust = 1
    IF dy > 31 AND m = 10 THEN m = 11: dy = 3: rollover = 1: adjust = 0
    IF dy > 30 AND m = 11 THEN m = 12: dy = 3: rollover = 1: adjust = 1
    IF dy > 31 AND m = 12 THEN y = 2034: m = 1: dy = 4: rollover = 1: adjust = 0
END IF
IF y = 2034 THEN
    IF dy > 31 AND m = 1 THEN m = 2: dy = 1: rollover = 1: adjust = 0
    IF dy > 28 AND m = 2 THEN m = 3: dy = 1: rollover = 1: adjust = 3
    IF dy > 31 AND m = 3 THEN m = 4: dy = 1: rollover = 1: adjust = 0
    IF dy > 30 AND m = 4 THEN m = 5: dy = 3: rollover = 1: adjust = 1
    IF dy > 31 AND m = 5 THEN m = 6: dy = 3: rollover = 1: adjust = 0
    IF dy > 30 AND m = 6 THEN m = 7: dy = 1: rollover = 1: adjust = 1
    IF dy > 31 AND m = 7 THEN m = 8: dy = 2: rollover = 1: adjust = 0
    IF dy > 31 AND m = 8 THEN m = 9: dy = 2: rollover = 1: adjust = 0
    IF dy > 30 AND m = 9 THEN m = 10: dy = 4: rollover = 1: adjust = 1
    IF dy > 31 AND m = 10 THEN m = 11: dy = 1: rollover = 1: adjust = 0
    IF dy > 30 AND m = 11 THEN m = 12: dy = 2: rollover = 1: adjust = 1
    IF dy > 31 AND m = 12 THEN y = 2035: m = 1: dy = 3: rollover = 1: adjust = 0
END IF
IF y = 2035 THEN
    IF dy > 31 AND m = 1 THEN m = 2: dy = 3: rollover = 1: adjust = 0
    IF dy > 28 AND m = 2 THEN m = 3: dy = 3: rollover = 1: adjust = 3
    IF dy > 31 AND m = 3 THEN m = 4: dy = 4: rollover = 1: adjust = 0
    IF dy > 30 AND m = 4 THEN m = 5: dy = 2: rollover = 1: adjust = 1
    IF dy > 31 AND m = 5 THEN m = 6: dy = 2: rollover = 1: adjust = 0
    IF dy > 30 AND m = 6 THEN m = 7: dy = 4: rollover = 1: adjust = 1
    IF dy > 31 AND m = 7 THEN m = 8: dy = 1: rollover = 1: adjust = 0
    IF dy > 31 AND m = 8 THEN m = 9: dy = 1: rollover = 1: adjust = 0
    IF dy > 30 AND m = 9 THEN m = 10: dy = 3: rollover = 1: adjust = 1
    IF dy > 31 AND m = 10 THEN m = 11: dy = 3: rollover = 1: adjust = 0
    IF dy > 30 AND m = 11 THEN m = 12: dy = 1: rollover = 1: adjust = 1
    IF dy > 31 AND m = 12 THEN y = 2036: m = 1: dy = 2: rollover = 1: adjust = 0
END IF
IF y = 2036 THEN
    IF dy > 31 AND m = 1 THEN m = 2: dy = 2: rollover = 1: adjust = 0
    IF dy > 29 AND m = 2 THEN m = 3: dy = 1: rollover = 1: adjust = 2
    IF dy > 31 AND m = 3 THEN m = 4: dy = 2: rollover = 1: adjust = 0
    IF dy > 30 AND m = 4 THEN m = 5: dy = 3: rollover = 1: adjust = 1
    IF dy > 31 AND m = 5 THEN m = 6: dy = 4: rollover = 1: adjust = 0
    IF dy > 30 AND m = 6 THEN m = 7: dy = 2: rollover = 1: adjust = 1
    IF dy > 31 AND m = 7 THEN m = 8: dy = 2: rollover = 1: adjust = 0
    IF dy > 31 AND m = 8 THEN m = 9: dy = 3: rollover = 1: adjust = 0
    IF dy > 30 AND m = 9 THEN m = 10: dy = 1: rollover = 1: adjust = 1
    IF dy > 31 AND m = 10 THEN m = 11: dy = 1: rollover = 1: adjust = 0
    IF dy > 30 AND m = 11 THEN m = 12: dy = 3: rollover = 1: adjust = 1
    IF dy > 31 AND m = 12 THEN y = 2037: m = 1: dy = 3: rollover = 1: adjust = 0
END IF
IF y = 2037 THEN
    IF dy > 31 AND m = 1 THEN m = 2: dy = 4: rollover = 1: adjust = 0
    IF dy > 28 AND m = 2 THEN m = 3: dy = 4: rollover = 1: adjust = 3
    IF dy > 31 AND m = 3 THEN m = 4: dy = 1: rollover = 1: adjust = 0
    IF dy > 30 AND m = 4 THEN m = 5: dy = 2: rollover = 1: adjust = 1
    IF dy > 31 AND m = 5 THEN m = 6: dy = 3: rollover = 1: adjust = 0
    IF dy > 30 AND m = 6 THEN m = 7: dy = 4: rollover = 1: adjust = 1
    IF dy > 31 AND m = 7 THEN m = 8: dy = 1: rollover = 1: adjust = 0
    IF dy > 31 AND m = 8 THEN m = 9: dy = 2: rollover = 1: adjust = 0
    IF dy > 30 AND m = 9 THEN m = 10: dy = 3: rollover = 1: adjust = 1
    IF dy > 31 AND m = 10 THEN m = 11: dy = 4: rollover = 1: adjust = 0
    IF dy > 30 AND m = 11 THEN m = 12: dy = 2: rollover = 1: adjust = 1
    IF dy > 31 AND m = 12 THEN y = 2038: m = 1: dy = 2: rollover = 1: adjust = 0
END IF
IF y = 2038 THEN
    IF dy > 31 AND m = 1 THEN m = 2: dy = 3: rollover = 1: adjust = 0
    IF dy > 28 AND m = 2 THEN m = 3: dy = 3: rollover = 1: adjust = 3
    IF dy > 31 AND m = 3 THEN m = 4: dy = 3: rollover = 1: adjust = 0
    IF dy > 30 AND m = 4 THEN m = 5: dy = 1: rollover = 1: adjust = 1
    IF dy > 31 AND m = 5 THEN m = 6: dy = 2: rollover = 1: adjust = 0
    IF dy > 30 AND m = 6 THEN m = 7: dy = 3: rollover = 1: adjust = 1
    IF dy > 31 AND m = 7 THEN m = 8: dy = 4: rollover = 1: adjust = 0
    IF dy > 31 AND m = 8 THEN m = 9: dy = 1: rollover = 1: adjust = 0
    IF dy > 30 AND m = 9 THEN m = 10: dy = 2: rollover = 1: adjust = 1
    IF dy > 31 AND m = 10 THEN m = 11: dy = 3: rollover = 1: adjust = 0
    IF dy > 30 AND m = 11 THEN m = 12: dy = 1: rollover = 1: adjust = 1
    IF dy > 31 AND m = 12 THEN y = 2039: m = 1: dy = 1: rollover = 1: adjust = 0
END IF
IF y = 2039 THEN
    IF dy > 31 AND m = 1 THEN m = 2: dy = 2: rollover = 1: adjust = 0
    IF dy > 28 AND m = 2 THEN m = 3: dy = 2: rollover = 1: adjust = 3
    IF dy > 31 AND m = 3 THEN m = 4: dy = 2: rollover = 1: adjust = 0
    IF dy > 30 AND m = 4 THEN m = 5: dy = 4: rollover = 1: adjust = 1
    IF dy > 31 AND m = 5 THEN m = 6: dy = 1: rollover = 1: adjust = 0
    IF dy > 30 AND m = 6 THEN m = 7: dy = 2: rollover = 1: adjust = 1
    IF dy > 31 AND m = 7 THEN m = 8: dy = 3: rollover = 1: adjust = 0
    IF dy > 31 AND m = 8 THEN m = 9: dy = 3: rollover = 1: adjust = 0
    IF dy > 30 AND m = 9 THEN m = 10: dy = 1: rollover = 1: adjust = 1
    IF dy > 31 AND m = 10 THEN m = 11: dy = 2: rollover = 1: adjust = 0
    IF dy > 30 AND m = 11 THEN m = 12: dy = 3: rollover = 1: adjust = 1
    IF dy > 31 AND m = 12 THEN y = 2040: m = 1: dy = 4: rollover = 1: adjust = 0
END IF
IF y = 2040 THEN
    IF dy > 31 AND m = 1 THEN m = 2: dy = 1: rollover = 1: adjust = 0
    IF dy > 29 AND m = 2 THEN m = 3: dy = 1: rollover = 1: adjust = 2
    IF dy > 31 AND m = 3 THEN m = 4: dy = 4: rollover = 1: adjust = 0
    IF dy > 30 AND m = 4 THEN m = 5: dy = 2: rollover = 1: adjust = 1
    IF dy > 31 AND m = 5 THEN m = 6: dy = 2: rollover = 1: adjust = 0
    IF dy > 30 AND m = 6 THEN m = 7: dy = 4: rollover = 1: adjust = 1
    IF dy > 31 AND m = 7 THEN m = 8: dy = 1: rollover = 1: adjust = 0
    IF dy > 31 AND m = 8 THEN m = 9: dy = 1: rollover = 1: adjust = 0
    IF dy > 30 AND m = 9 THEN m = 10: dy = 3: rollover = 1: adjust = 1
    IF dy > 31 AND m = 10 THEN m = 11: dy = 3: rollover = 1: adjust = 0
    IF dy > 30 AND m = 11 THEN m = 12: dy = 1: rollover = 1: adjust = 1
    IF dy > 31 AND m = 12 THEN y = 2041: m = 1: dy = 2: rollover = 1: adjust = 0
END IF

RETURN


Now that is how I did it, but I still have to plug in the right data for each month starting after 2020, will be doing that tomorrow, but thought I would give you an idea of how I handled it.

Can anyone thing of a better way?


Russ Campbell
Russ Campbell
rcamp48@rogers.com
BBS Files Programmer

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: How to calculate the day of the week for 40 years into the future
« Reply #1 on: January 04, 2020, 06:08:46 am »
Hi. Try some mine functions. First TEST it, if it works as is expected.

Code: QB64: [Select]
  1. 'function GETDAYNAME parameters: YEAR, MONTH, DAY
  2. 'listing of Tuesdays and Thursdays for 40 years
  3.  
  4. d = __GETDAY - 1
  5. DIM SHARED VirtualYear
  6. VirtualYear = 2020
  7.  
  8. FOR l = 1 TO 366 * 40
  9.     d = d + 1
  10.     IF ISLEAPYEAR(VirtualYear) AND d > 366 THEN VirtualYear = VirtualYear + 1: d = d - 366
  11.     IF ISLEAPYEAR(VirtualYear) = 0 AND d > 365 THEN VirtualYear = VirtualYear + 1: d = d - 365
  12.     today$ = ""
  13.     DO UNTIL today$ = "Thursday" OR today$ = "Tuesday"
  14.         today$ = GETDAYNAME(VirtualYear, 1, d)
  15.         d = d + 1
  16.     LOOP
  17.     d = d - 1
  18.     day = GETDAYNR(VirtualYear, 1, d)
  19.     realdate$ = GETDATE$(day, VirtualYear)
  20.  
  21.     PRINT "Next date is "; realdate$; " "; GETDAYNAME(VirtualYear, 1, d)
  22.     SLEEP
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29. FUNCTION GETDAYNR (y, m, d) 'insert year, month and day and function calculate which day in year it is
  30.     FOR month = 1 TO m
  31.         IF ISLEAPYEAR(y) = 0 THEN
  32.             SELECT CASE month
  33.                 CASE 1: m = 31
  34.                 CASE 2: m = 28
  35.                 CASE 3: m = 31
  36.                 CASE 4: m = 30
  37.                 CASE 5: m = 31
  38.                 CASE 6: m = 30
  39.                 CASE 7: m = 31
  40.                 CASE 8: m = 31
  41.                 CASE 9: m = 30
  42.                 CASE 10: m = 31
  43.                 CASE 11: m = 30
  44.                 CASE 12: m = 31
  45.             END SELECT
  46.         ELSE
  47.             SELECT CASE month
  48.                 CASE 1: m = 31
  49.                 CASE 2: m = 29
  50.                 CASE 3: m = 31
  51.                 CASE 4: m = 30
  52.                 CASE 5: m = 31
  53.                 CASE 6: m = 30
  54.                 CASE 7: m = 31
  55.                 CASE 8: m = 31
  56.                 CASE 9: m = 30
  57.                 CASE 10: m = 31
  58.                 CASE 11: m = 30
  59.                 CASE 12: m = 31
  60.             END SELECT
  61.         END IF
  62.         GETDAYNR = GETDAYNR + m
  63.     NEXT
  64.     GETDAYNR = GETDAYNR - (m - d)
  65.  
  66. FUNCTION __GETDAY
  67.     __GETDAY = VAL(MID$(DATE$, 4, 2))
  68.  
  69.  
  70. FUNCTION GETDATE$ (NrOfTheDayInYear, y) 'return date 'YYYYMMDD in year y
  71.  
  72.     'spocitat mesic
  73.     FOR month = 1 TO 12
  74.         IF ISLEAPYEAR(y) = 0 THEN
  75.             SELECT CASE month
  76.                 CASE 1: m = 31
  77.                 CASE 2: m = 28
  78.                 CASE 3: m = 31
  79.                 CASE 4: m = 30
  80.                 CASE 5: m = 31
  81.                 CASE 6: m = 30
  82.                 CASE 7: m = 31
  83.                 CASE 8: m = 31
  84.                 CASE 9: m = 30
  85.                 CASE 10: m = 31
  86.                 CASE 11: m = 30
  87.                 CASE 12: m = 31
  88.             END SELECT
  89.         ELSE
  90.             SELECT CASE month
  91.                 CASE 1: m = 31
  92.                 CASE 2: m = 29
  93.                 CASE 3: m = 31
  94.                 CASE 4: m = 30
  95.                 CASE 5: m = 31
  96.                 CASE 6: m = 30
  97.                 CASE 7: m = 31
  98.                 CASE 8: m = 31
  99.                 CASE 9: m = 30
  100.                 CASE 10: m = 31
  101.                 CASE 11: m = 30
  102.                 CASE 12: m = 31
  103.             END SELECT
  104.         END IF
  105.         oldm = om
  106.         om = om + m
  107.         IF om >= NrOfTheDayInYear AND oldm < NrOfTheDayInYear THEN EXIT FOR
  108.     NEXT
  109.     day = NrOfTheDayInYear - om + m
  110.     day$ = STR$(day): IF LEN(day$) < 3 THEN day$ = "0" + LTRIM$(day$)
  111.     month$ = STR$(month): IF LEN(month$) < 3 THEN month$ = "0" + LTRIM$(month$)
  112.  
  113.     GETDATE$ = LTRIM$(STR$(y)) + "-" + LTRIM$(month$) + "-" + LTRIM$(day$)
  114.  
  115.  
  116.  
  117.  
  118. FUNCTION ISLEAPYEAR (year)
  119.     IF year MOD 4 = 0 AND year MOD 100 THEN ISLEAPYEAR = 1
  120.     IF year MOD 100 = 0 AND year MOD 400 = 0 THEN ISLEAPYEAR = 1
  121.  
  122. FUNCTION GETDAYNAME$ (year, month, day) 'otestovano brutalne, fuguje skutecne spravne!
  123.     '  IF year < 1900 THEN GETDAYNAME$ = "Invalid Year ( <1900 ).": EXIT FUNCTION
  124.     'spocitat pocet mesicu od ledna 1900:
  125.     DIM om AS LONG, m AS LONG, days AS LONG
  126.     days = day
  127.     FOR yyr = 1 TO year
  128.         IF yyr = year THEN monthend = month ELSE monthend = 12
  129.         FOR mont = 1 TO monthend
  130.             IF ISLEAPYEAR(yyr) = 0 THEN
  131.                 SELECT CASE mont
  132.                     CASE 1: m = 31
  133.                     CASE 2: m = 28
  134.                     CASE 3: m = 31
  135.                     CASE 4: m = 30
  136.                     CASE 5: m = 31
  137.                     CASE 6: m = 30
  138.                     CASE 7: m = 31
  139.                     CASE 8: m = 31
  140.                     CASE 9: m = 30
  141.                     CASE 10: m = 31
  142.                     CASE 11: m = 30
  143.                     CASE 12: m = 31
  144.                 END SELECT
  145.             ELSE
  146.                 SELECT CASE mont
  147.                     CASE 1: m = 31
  148.                     CASE 2: m = 29
  149.                     CASE 3: m = 31
  150.                     CASE 4: m = 30
  151.                     CASE 5: m = 31
  152.                     CASE 6: m = 30
  153.                     CASE 7: m = 31
  154.                     CASE 8: m = 31
  155.                     CASE 9: m = 30
  156.                     CASE 10: m = 31
  157.                     CASE 11: m = 30
  158.                     CASE 12: m = 31
  159.                 END SELECT
  160.             END IF
  161.             om = m
  162.             days = days + m
  163.         NEXT
  164.     NEXT
  165.     days = days - m - 1
  166.     '  PRINT "Dnu:"; Days
  167.     a = (days MOD 7) '0 = pondeli
  168.     RESTORE nms
  169.     FOR r = 0 TO a
  170.         READ GETDAYNAME$
  171.     NEXT
  172.     nms:
  173.     DATA Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday
  174.  
  175.  
  176. FUNCTION GetDay$ (mm, dd, yyyy) 'use 4 digit year
  177.     'From Zeller's congruence: https://en.wikipedia.org/wiki/Zeller%27s_congruence
  178.     IF mm < 3 THEN mm = mm + 12: yyyy = yyyy - 1
  179.     century = yyyy MOD 100
  180.     zerocentury = yyyy \ 100
  181.     result = (dd + INT(13 * (mm + 1) / 5) + century + INT(century / 4) + INT(zerocentury / 4) + 5 * zerocentury) MOD 7
  182.     SELECT CASE result
  183.         CASE 0: GetDay$ = "Saturday"
  184.         CASE 1: GetDay$ = "Sunday"
  185.         CASE 2: GetDay$ = "Monday"
  186.         CASE 3: GetDay$ = "Tuesday"
  187.         CASE 4: GetDay$ = "Wednesday"
  188.         CASE 5: GetDay$ = "Thursday"
  189.         CASE 6: GetDay$ = "Friday"
  190.     END SELECT
  191.  
  192.  
  193.  

This is fast writed code without warranty!
« Last Edit: January 04, 2020, 06:23:45 am by Petr »

Offline rcamp48

  • Newbie
  • Posts: 62
    • View Profile
Re: How to calculate the day of the week for 40 years into the future
« Reply #2 on: January 04, 2020, 07:30:57 am »
Nice code, I will give it a try later on, should save me a lot of lines of code...... Thanks...

Russ
Russ Campbell
rcamp48@rogers.com
BBS Files Programmer

Offline rcamp48

  • Newbie
  • Posts: 62
    • View Profile
Re: How to calculate the day of the week for 40 years into the future
« Reply #3 on: January 05, 2020, 03:43:54 am »
 OK I have tried your code but its not quite what I want, I want to start from the previous draw date, not the current date, but I have incorporated your code into both of my programs....

The problem with it the way it is , is that if the draw database is not up to date, it ignores everything before the current date and asks for the next Tuesday or Wednesday after the current date.

Russ

 
 

PS: You need the rest of the data files in my original program to run this program.

« Last Edit: January 05, 2020, 03:47:40 am by rcamp48 »
Russ Campbell
rcamp48@rogers.com
BBS Files Programmer

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: How to calculate the day of the week for 40 years into the future
« Reply #4 on: January 08, 2020, 02:23:35 pm »
Rcamp, feel free to use some of my code I made for my Calendar Maker. People in this forum helped me make this a few months ago. It uses equations to know what day of the week it is from 100's of years ago to 9999 A.D.

Code: QB64: [Select]
  1. 'This is my very first calendar making program!
  2. 'Thanks to the guys from the QB64.org forum for the help: bplus, SMcNeill, euklides, and TempodiBasic!
  3. 'This is a freeware program like all my other programs and games, only free.
  4. 'Feel free to use this code in your own programs.
  5. 'This version has the ability to add info or holidays to dates.
  6. 'Made on Thursday, September 19, 2019 by Ken G.
  7.  
  8. start:
  9. _TITLE "Calendar Maker"
  10. _LIMIT 1000
  11. DIM newinfo$(50)
  12. DIM dayinfo(50)
  13. dd = 0
  14. leap = 0
  15. m = 0
  16. mm = 0
  17. y = 0
  18. yy = 0
  19. w = 0
  20. weekday = 0
  21. days = 0
  22. holidays = 0
  23. SCREEN _NEWIMAGE(800, 600, 32)
  24. PRINT "                                  Monthly Calendar Maker"
  25. PRINT "                                        By Ken G."
  26. PRINT "                         With some help from the QB64.org Forum guys!"
  27. PRINT "          This program will make a calendar for the year and month you want."
  28. PRINT "          It will also name some U.S. holidays on their dates if you choose that."
  29. PRINT "          You also can add holidays or info to any day you wish with up to 12"
  30. PRINT "          letters, numbers, symbols, or spaces."
  31. PRINT "          This uses the Gregorian Calendar which became common practice in"
  32. PRINT "          England in 1753 and we still use it today."
  33. PRINT "          First make a calendar, then if you want to save it as a .bmp file,"
  34. PRINT "          press the 'S' key and it will save it as the month and year for its name."
  35. PRINT "          For example, if you made a calendar for January 2020 and wish to save it,"
  36. PRINT "          press the 'S' key and it will save it as 1-2020.bmp"
  37. PRINT "          If you wish to print your calendar on your printer, press 'P' once."
  38. PRINT "          Feel free to print as many times as you wish. They take up 1 page each."
  39. PRINT "          If you save the .bmp calendar, it will be put in the same directory as this program."
  40. PRINT "          To switch to the last month use the left arrow key, to the next month the right arrow key."
  41. PRINT "          Switching months with the arrow keys will not save your new date info if you come back."
  42. PRINT "          To make a different calendar without saving, press the Space Bar."
  43. PRINT "          Keyboard commands will be listed on the title bar of the window."
  44. again1:
  45. INPUT "          Type the year here (1753-9999): ", y
  46. IF y <> INT(y) THEN PRINT "Cannot use decimals, try again.": GOTO again1:
  47. IF y < 1753 OR y > 9999 THEN PRINT "The year can only be between 1753 and 9999, try again.": GOTO again1:
  48. again2:
  49. INPUT "          Type the month here (1-12): ", m
  50. IF m <> INT(m) THEN PRINT "Cannot use decimals, try again.": GOTO again2:
  51. IF m < 1 OR m > 12 THEN PRINT "1-12 only, try again.": GOTO again2:
  52. INPUT "          Do you want U.S. holidays added (Y/N)?", hol$
  53. IF LEFT$(hol$, 1) = "y" OR LEFT$(hol$, 1) = "Y" THEN holidays = 1
  54. INPUT "          Do you want to add your own holidays or info (Y/N)?", adding$
  55. calculate:
  56. info = 0
  57. infos = 0
  58. 'Get the month name.
  59. IF m = 1 THEN month$ = " January"
  60. IF m = 2 THEN month$ = "February"
  61. IF m = 3 THEN month$ = "  March"
  62. IF m = 4 THEN month$ = "  April"
  63. IF m = 5 THEN month$ = "  May"
  64. IF m = 6 THEN month$ = "  June"
  65. IF m = 7 THEN month$ = "  July"
  66. IF m = 8 THEN month$ = " August"
  67. IF m = 9 THEN month$ = "September"
  68. IF m = 10 THEN month$ = " October"
  69. IF m = 11 THEN month$ = "November"
  70. IF m = 12 THEN month$ = "December"
  71.  
  72. 'Calculate to see if it's a Leap Year.
  73. IF m <> 2 THEN GOTO nex:
  74. IF y / 400 = INT(y / 400) THEN leap = 1: GOTO more:
  75. IF y / 4 = INT(y / 4) THEN leap = 1
  76. IF y / 100 = INT(y / 100) THEN leap = 0
  77.  
  78. 'Get the number of days for each month.
  79. more:
  80. IF leap = 1 THEN days = 29
  81. IF leap = 0 THEN days = 28
  82. GOTO weekday:
  83. nex:
  84. IF m = 1 THEN days = 31
  85. IF m = 3 THEN days = 31
  86. IF m = 4 THEN days = 30
  87. IF m = 5 THEN days = 31
  88. IF m = 6 THEN days = 30
  89. IF m = 7 THEN days = 31
  90. IF m = 8 THEN days = 31
  91. IF m = 9 THEN days = 30
  92. IF m = 10 THEN days = 31
  93. IF m = 11 THEN days = 30
  94. IF m = 12 THEN days = 31
  95. weekday:
  96.  
  97. 'Set the month, year, and weekday variables to start with.
  98. mm = m
  99. yy = y
  100. GetDay mm, dd, y, weekday
  101.  
  102.  
  103. IF LEFT$(adding$, 1) = "y" OR LEFT$(adding$, 1) = "Y" THEN GOSUB adding:
  104. adding$ = ""
  105.  
  106. 'This section makes the calendar graph.
  107. make:
  108. SCREEN _NEWIMAGE(800, 600, 32)
  109. LINE (0, 0)-(800, 600), _RGB32(255, 255, 255), BF
  110. _TITLE "Press 'S' to Save, 'P' to Print, Left and Right Arrow Keys To Switch Months, Space Bar For Different One, or 'Esc' to Quit."
  111. COLOR _RGB32(0, 0, 0), _RGB32(255, 255, 255)
  112. LOCATE 3, 42: PRINT month$; "  "; yy
  113.  
  114. FOR x = 20 TO 780 STEP 108
  115.     LINE (x, 100)-(x, 580), _RGB32(0, 0, 0)
  116. FOR z = 100 TO 580 STEP 80
  117.     LINE (16, z)-(780, z), _RGB32(0, 0, 0)
  118.  
  119. LOCATE 5, 8: PRINT "SUNDAY"
  120. LOCATE 5, 21: PRINT "MONDAY"
  121. LOCATE 5, 34: PRINT "TUESDAY"
  122. LOCATE 5, 47: PRINT "WEDNESDAY"
  123. LOCATE 5, 60: PRINT "THURSDAY"
  124. LOCATE 5, 75: PRINT "FRIDAY"
  125. LOCATE 5, 87: PRINT "SATURDAY"
  126.  
  127. 'Finding Date of Easter
  128. PQA = yy
  129. GOSUB PAQUES
  130. 'month = PQM, day = PQJ, year = PQA
  131.  
  132. 'This section puts the right dates and holidays in the right squares for the calendar.
  133. w = (weekday * 108) + 25
  134. FOR weeky = 110 TO 570 STEP 80
  135.     FOR dayx = w TO 692 STEP 108
  136.         _LIMIT 1000
  137.         dd = dd + 1
  138.         GetDay mm, dd, y, weekday
  139.         IF weekday = 1 THEN GOSUB coloring:
  140.         IF weekday <> 1 THEN COLOR _RGB32(0, 0, 0), _RGB32(255, 255, 255)
  141.         dd$ = STR$(dd)
  142.         _FONT 8
  143.         IF dd = dayinfo(infos) THEN
  144.             GOSUB coloring:
  145.             i = LEN(newinfo$(infos))
  146.             IF i < 8 THEN ii = 25
  147.             IF i > 7 AND i < 12 THEN ii = 11
  148.             IF i > 11 AND i < 14 THEN ii = 5
  149.             IF i > 13 THEN ii = 2
  150.             _PRINTSTRING (dayx + ii, weeky + 20), newinfo$(infos)
  151.             infos = infos + 1
  152.             ye = 1
  153.         END IF
  154.         IF holidays = 0 THEN GOTO skip:
  155.         IF m = 1 AND dd = 1 THEN
  156.             GOSUB coloring:
  157.             _PRINTSTRING (dayx + 15, weeky + 60), "New Years"
  158.         END IF
  159.         IF m = 1 AND weekday = 2 AND dd > 14 AND dd < 22 THEN
  160.             GOSUB coloring:
  161.             _PRINTSTRING (dayx + 25, weeky + 60), "MLK Jr."
  162.         END IF
  163.         IF m = 2 AND dd = 2 THEN
  164.             GOSUB coloring:
  165.             _PRINTSTRING (dayx + 13, weeky + 60), "Groundhog"
  166.         END IF
  167.         IF m = 2 AND weekday = 2 AND dd > 14 AND dd < 22 THEN
  168.             GOSUB coloring:
  169.             _PRINTSTRING (dayx + 10, weeky + 60), "Presidents"
  170.         END IF
  171.         IF m = 2 AND dd = 14 THEN
  172.             GOSUB coloring:
  173.             _PRINTSTRING (dayx + 10, weeky + 60), "Valentines"
  174.         END IF
  175.         IF m = 3 AND dd = 17 THEN
  176.             GOSUB coloring:
  177.             _PRINTSTRING (dayx + 5, weeky + 60), "St. Patrick"
  178.         END IF
  179.         IF m = PQM AND dd = PQJ THEN
  180.             GOSUB coloring:
  181.             _PRINTSTRING (dayx + 25, weeky + 60), "Easter"
  182.         END IF
  183.         IF m = 4 AND dd > 23 AND weekday = 7 THEN
  184.             GOSUB coloring:
  185.             _PRINTSTRING (dayx + 25, weeky + 60), "Arbor"
  186.         END IF
  187.         IF m = 5 AND weekday = 0 AND dd > 14 AND dd < 22 THEN
  188.             GOSUB coloring:
  189.             _PRINTSTRING (dayx + 2, weeky + 60), "Armed Forces"
  190.         END IF
  191.         IF m = 5 AND weekday = 2 AND dd > 24 THEN
  192.             GOSUB coloring:
  193.             _PRINTSTRING (dayx + 15, weeky + 60), "Memorial"
  194.         END IF
  195.         IF m = 5 AND weekday = 1 AND dd > 7 AND dd < 15 THEN
  196.             GOSUB coloring:
  197.             _PRINTSTRING (dayx + 2, weeky + 60), "Mother's Day"
  198.         END IF
  199.         IF m = 6 AND weekday = 1 AND dd > 14 AND dd < 22 THEN
  200.             GOSUB coloring:
  201.             _PRINTSTRING (dayx + 2, weeky + 60), "Father's Day"
  202.         END IF
  203.         IF m = 6 AND dd = 14 THEN
  204.             GOSUB coloring:
  205.             _PRINTSTRING (dayx + 35, weeky + 60), "Flag"
  206.         END IF
  207.         IF m = 7 AND dd = 4 THEN
  208.             GOSUB coloring:
  209.             _PRINTSTRING (dayx + 2, weeky + 60), "Independence"
  210.         END IF
  211.         IF m = 9 AND weekday = 2 AND dd < 8 THEN
  212.             GOSUB coloring:
  213.             _PRINTSTRING (dayx + 27, weeky + 60), "Labor"
  214.         END IF
  215.         IF m = 10 AND dd > 9 AND dd < 16 AND weekday = 2 THEN
  216.             GOSUB coloring:
  217.             _PRINTSTRING (dayx + 17, weeky + 60), "Columbus"
  218.         END IF
  219.         IF m = 10 AND dd = 31 THEN
  220.             GOSUB coloring:
  221.             _PRINTSTRING (dayx + 15, weeky + 60), "Halloween"
  222.         END IF
  223.         IF m = 11 AND dd = 11 THEN
  224.             GOSUB coloring:
  225.             _PRINTSTRING (dayx + 19, weeky + 60), "Veterans"
  226.         END IF
  227.         IF m = 11 AND dd > 21 AND dd < 29 AND weekday = 5 THEN
  228.             GOSUB coloring:
  229.             _PRINTSTRING (dayx + 2, weeky + 60), "Thanksgiving"
  230.         END IF
  231.         IF m = 12 AND dd = 25 THEN
  232.             GOSUB coloring:
  233.             _PRINTSTRING (dayx + 15, weeky + 60), "Christmas"
  234.         END IF
  235.         skip:
  236.         ye = 0
  237.         _FONT 16
  238.         _PRINTSTRING (dayx, weeky), dd$
  239.         _FONT 8
  240.         IF dd = days THEN _FONT 16: GOTO more2:
  241.     NEXT dayx
  242.     w = 25
  243. NEXT weeky
  244.  
  245. more2:
  246. _LIMIT 1000
  247. a$ = INKEY$
  248. IF a$ = CHR$(27) THEN CLS: PRINT: PRINT: PRINT "Goodbye.": END
  249. IF a$ = "s" OR a$ = "S" THEN GOTO saving:
  250. IF a$ = " " THEN GOTO start:
  251. IF a$ = "p" OR a$ = "P" THEN
  252.     'printer prep (code copied and pasted from bplus Free Calendar Program)
  253.     YMAX = _HEIGHT: XMAX = _WIDTH
  254.     landscape& = _NEWIMAGE(YMAX, XMAX, 32)
  255.     _MAPTRIANGLE (XMAX, 0)-(0, 0)-(0, YMAX), 0 TO(0, 0)-(0, XMAX)-(YMAX, XMAX), landscape&
  256.     _MAPTRIANGLE (XMAX, 0)-(XMAX, YMAX)-(0, YMAX), 0 TO(0, 0)-(YMAX, 0)-(YMAX, XMAX), landscape&
  257.     _PRINTIMAGE landscape&
  258.  
  259. IF a$ = CHR$(0) + CHR$(77) THEN
  260.     m = m + 1
  261.     IF m > 12 THEN
  262.         m = 1
  263.         yy = yy + 1
  264.     END IF
  265.     y = yy
  266.     IF y > 9999 THEN y = 1753
  267.     dd = 0
  268.     leap = 0
  269.     _DELAY .1
  270.     CLS
  271.     GOTO calculate:
  272. IF a$ = CHR$(0) + CHR$(75) THEN
  273.     m = m - 1
  274.     IF m < 1 THEN
  275.         m = 12
  276.         yy = yy - 1
  277.     END IF
  278.     y = yy
  279.     IF y < 1753 THEN y = 9999
  280.     dd = 0
  281.     leap = 0
  282.     _DELAY .1
  283.     CLS
  284.     GOTO calculate:
  285.  
  286. GOTO more2:
  287.  
  288. adding:
  289. add:
  290. olddayinfo = dayinfo(info)
  291. info = info + 1
  292. infos = 1
  293. adding2:
  294. IF info > days THEN PRINT "You have reached the maximum amount of holidays or info for this month.": INPUT "Press enter to create calendar.", pe$: RETURN
  295. PRINT "Your dates must go in order here."
  296. PRINT "for example, you cannot put info for day 15 and then put info for day 1."
  297. PRINT "They must all follow from smallest number to highest number or it will tell you to start over again."
  298. PRINT "Also, you cannot change a day by doing it over again, so if you mess up, create a new month."
  299. PRINT info; ". ";
  300. INPUT "Which day of the month for new holiday or information: ", dayinfo(info)
  301. IF dayinfo(info) > days THEN PRINT "That day is not on this calendar, try again.": GOTO adding2:
  302. IF dayinfo(info) < 1 THEN PRINT "You cannot type a date less than 1, try again.": GOTO adding2:
  303. IF dayinfo(info) <> INT(dayinfo(info)) THEN PRINT "You cannot type a decimal for a date, try again.": GOTO adding2:
  304. IF dayinfo(info) < olddayinfo THEN
  305.     PRINT
  306.     PRINT "You have put a date before your previous one which cannot work, start over from your first date."
  307.     FOR dl = 1 TO info
  308.         newinfo$(dl) = ""
  309.         dayinfo(dl) = 0
  310.     NEXT dl
  311.     olddayinfo = 0
  312.     info = 0
  313.     GOTO add:
  314. adding3:
  315. PRINT "Type up to 12 letters, numbers, or spaces that will be put for that day."
  316. INPUT "->", newinfo$(info)
  317. infoamount = LEN(newinfo$(info))
  318. IF infoamount > 12 THEN PRINT "Too long, try again.": GOTO adding3:
  319. IF infoamount < 1 THEN PRINT "Nothing typed, try again.": GOTO adding3:
  320. INPUT "Do you want to add more (Y/N):", yn$
  321. IF LEFT$(yn$, 1) = "y" OR LEFT$(yn$, 1) = "Y" THEN GOTO adding:
  322.  
  323. 'Color all Sundays and holidays
  324. coloring:
  325. IF ye = 1 THEN RETURN
  326. LINE (dayx - 4, weeky - 9)-(dayx + 102, weeky + 68), _RGB32(255, 255, 127), BF: COLOR _RGB32(0, 0, 0), _RGB32(255, 255, 127)
  327.  
  328.  
  329. 'Find the right date for Easter.
  330. PAQUES:
  331. PQM = INT(PQA / 100): PQ1 = PQA - PQM * 100: PQJ = INT(((PQA / 19 - INT(PQA / 19)) + .001) * 19)
  332. PQ2 = INT(PQM / 4): PQ3 = INT(((PQM / 4) - PQ2 + .001) * 4): PQ4 = INT((8 + PQM) / 25)
  333. PQ5 = INT((1 + PQM - PQ4 + .001) / 3): PQ4 = (15 + 19 * PQJ + PQM - PQ2 - PQ5 + .001) / 30: PQ4 = PQ4 - INT(PQ4)
  334. PQ4 = INT(PQ4 * 30): PQ5 = INT(PQ1 / 4): PQ6 = ((PQ1 / 4) - PQ5) * 4
  335. PQ7 = (32 + 2 * PQ3 + 2 * PQ5 - PQ4 - PQ6 + .001) / 7: PQ7 = (PQ7 - INT(PQ7)) * 7: PQ6 = (PQJ + 11 * PQ4 + 22 * PQ7) / 451
  336. PQ6 = INT(PQ6): PQ2 = (114 + PQ4 + PQ7 - 7 * PQ6) / 31: PQM = INT(PQ2): PQJ = INT((PQ2 - PQM + .001) * 31 + 1)
  337.  
  338.  
  339. 'This section saves the calendar to a BMP file along with the SUB at the end of this program.
  340. saving:
  341. mo$ = STR$(m)
  342. mo$ = LTRIM$(RTRIM$(mo$))
  343. year$ = STR$(yy)
  344. year$ = LTRIM$(RTRIM$(year$))
  345. nm$ = mo$ + "-"
  346. nm$ = LTRIM$(RTRIM$(nm$))
  347. nm$ = nm$ + year$
  348. nm$ = LTRIM$(RTRIM$(nm$))
  349. SaveImage 0, nm$ 'saves entire program screen,"
  350. nm2$ = nm$ + ".bmp"
  351. nm2$ = LTRIM$(RTRIM$(nm2$))
  352. PRINT "                                           Saving"
  353. PRINT "                          "; nm2$; " has been saved to your computer."
  354. INPUT "                         Do you wish to make another calendar (Y/N)"; ag$
  355. IF LEFT$(ag$, 1) = "y" OR LEFT$(ag$, 1) = "Y" THEN GOTO start:
  356. PRINT "                         Goodbye."
  357.  
  358. weekdays:
  359.  
  360. 'This section gets the right weekday.
  361. SUB GetDay (mm, dd, y, weekday) 'use 4 digit year
  362.     'From Zeller's congruence: https://en.wikipedia.org/wiki/Zeller%27s_congruence
  363.     IF mm < 3 THEN mm = mm + 12: y = y - 1
  364.     century = y MOD 100
  365.     zerocentury = y \ 100
  366.     weekday = (dd + INT(13 * (mm + 1) / 5) + century + INT(century / 4) + INT(zerocentury / 4) + 5 * zerocentury) MOD 7
  367.  
  368. 'This section saves the .bmp picture file.
  369. SUB SaveImage (image AS LONG, filename AS STRING)
  370.     bytesperpixel& = _PIXELSIZE(image&)
  371.     IF bytesperpixel& = 0 THEN PRINT "Text modes unsupported!": END
  372.     IF bytesperpixel& = 1 THEN bpp& = 8 ELSE bpp& = 24
  373.     x& = _WIDTH(image&)
  374.     y& = _HEIGHT(image&)
  375.     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)
  376.     IF bytesperpixel& = 1 THEN
  377.         FOR c& = 0 TO 255 ' read BGR color settings from JPG image + 1 byte spacer(CHR$(0))
  378.             cv& = _PALETTECOLOR(c&, image&) ' color attribute to read.
  379.             b$ = b$ + CHR$(_BLUE32(cv&)) + CHR$(_GREEN32(cv&)) + CHR$(_RED32(cv&)) + CHR$(0) 'spacer byte
  380.         NEXT
  381.     END IF
  382.     MID$(b$, 11, 4) = MKL$(LEN(b$)) ' image pixel data offset(BMP header)
  383.     lastsource& = _SOURCE
  384.     _SOURCE image&
  385.     IF ((x& * 3) MOD 4) THEN padder$ = STRING$(4 - ((x& * 3) MOD 4), 0)
  386.     FOR py& = y& - 1 TO 0 STEP -1 ' read JPG image pixel color data
  387.         r$ = ""
  388.         FOR px& = 0 TO x& - 1
  389.             c& = POINT(px&, py&) 'POINT 32 bit values are large LONG values
  390.             IF bytesperpixel& = 1 THEN r$ = r$ + CHR$(c&) ELSE r$ = r$ + LEFT$(MKL$(c&), 3)
  391.         NEXT px&
  392.         d$ = d$ + r$ + padder$
  393.     NEXT py&
  394.     _SOURCE lastsource&
  395.     MID$(b$, 35, 4) = MKL$(LEN(d$)) ' image size(BMP header)
  396.     b$ = b$ + d$ ' total file data bytes to create file
  397.     MID$(b$, 3, 4) = MKL$(LEN(b$)) ' size of data file(BMP header)
  398.     IF LCASE$(RIGHT$(filename$, 4)) <> ".bmp" THEN ext$ = ".bmp"
  399.     f& = FREEFILE
  400.     OPEN filename$ + ext$ FOR OUTPUT AS #f&: CLOSE #f& ' erases an existing file
  401.     OPEN filename$ + ext$ FOR BINARY AS #f&
  402.     PUT #f&, , b$
  403.     CLOSE #f&
  404.  

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: How to calculate the day of the week for 40 years into the future
« Reply #5 on: January 08, 2020, 04:28:07 pm »
Hi Rcamp,

Sorry for waiting, i have not enought time for all my activities. Here is small upgrade my previous source code, now you can set own start day, month and year and set how much next Tuesdays and Thursdays you need to search. Please replace function GETDAYNR in your source code with upgraded version from this source code.

Code: QB64: [Select]
  1. 'function GETDAYNAME parameters: YEAR, MONTH, DAY
  2. 'listing of Tuesdays and Thursdays for 40 years
  3. 'FUNCTION GETDAYNR is upgraded and must be copyed to your program for correct work!
  4.  
  5.  
  6. DIM SHARED VirtualYear
  7.  
  8. 'DIM D AS INTEGER, Mnth AS INTEGER, VirtualYear AS INTEGER
  9.  
  10.  
  11. INPUT "Insert DAY, MONTH, YEAR: "; D, Mnth, VirtualYear
  12. INPUT "How much days find"; total
  13. IF Mnth < 0 OR Mnth > 12 THEN PRINT "Invalid value for month": SLEEP 2: END
  14. IF D < 0 OR D > 31 THEN PRINT "Invalid value for day": SLEEP 2: END
  15.  
  16.  
  17.  
  18. FOR l = 1 TO total
  19.     D = D + 1
  20.     IF ISLEAPYEAR(VirtualYear) AND D > 366 THEN VirtualYear = VirtualYear + 1: D = D - 366
  21.     IF ISLEAPYEAR(VirtualYear) = 0 AND D > 365 THEN VirtualYear = VirtualYear + 1: D = D - 365
  22.     today$ = ""
  23.     DO UNTIL today$ = "Thursday" OR today$ = "Tuesday"
  24.         today$ = GETDAYNAME(VirtualYear, Mnth, D)
  25.         D = D + 1
  26.     LOOP
  27.     D = D - 1
  28.  
  29.     DAY = GETDAYNR(VirtualYear, Mnth, D)
  30.     realdate$ = GETDATE$(DAY, VirtualYear)
  31.  
  32.     PRINT "Next date is "; realdate$; " "; GETDAYNAME(VirtualYear, Mnth, D)
  33.     SLEEP
  34.  
  35.  
  36. FUNCTION GETDAYNR (y, mn, d) 'insert year, month and day and function calculate which day in year it is
  37.     FOR month = 1 TO mn
  38.         IF ISLEAPYEAR(y) = 0 THEN
  39.             SELECT CASE month
  40.                 CASE 1: m = 31
  41.                 CASE 2: m = 28
  42.                 CASE 3: m = 31
  43.                 CASE 4: m = 30
  44.                 CASE 5: m = 31
  45.                 CASE 6: m = 30
  46.                 CASE 7: m = 31
  47.                 CASE 8: m = 31
  48.                 CASE 9: m = 30
  49.                 CASE 10: m = 31
  50.                 CASE 11: m = 30
  51.                 CASE 12: m = 31
  52.             END SELECT
  53.         ELSE
  54.             SELECT CASE month
  55.                 CASE 1: m = 31
  56.                 CASE 2: m = 29
  57.                 CASE 3: m = 31
  58.                 CASE 4: m = 30
  59.                 CASE 5: m = 31
  60.                 CASE 6: m = 30
  61.                 CASE 7: m = 31
  62.                 CASE 8: m = 31
  63.                 CASE 9: m = 30
  64.                 CASE 10: m = 31
  65.                 CASE 11: m = 30
  66.                 CASE 12: m = 31
  67.             END SELECT
  68.         END IF
  69.         GETDAYNR = GETDAYNR + m
  70.     NEXT
  71.     GETDAYNR = GETDAYNR - (m - d)
  72.  
  73. FUNCTION __GETDAY
  74.     __GETDAY = VAL(MID$(DATE$, 4, 2))
  75.  
  76.  
  77. FUNCTION GETDATE$ (NrOfTheDayInYear, y) 'return date 'YYYYMMDD in year y
  78.     FOR month = 1 TO 12
  79.         IF ISLEAPYEAR(y) = 0 THEN
  80.             SELECT CASE month
  81.                 CASE 1: m = 31
  82.                 CASE 2: m = 28
  83.                 CASE 3: m = 31
  84.                 CASE 4: m = 30
  85.                 CASE 5: m = 31
  86.                 CASE 6: m = 30
  87.                 CASE 7: m = 31
  88.                 CASE 8: m = 31
  89.                 CASE 9: m = 30
  90.                 CASE 10: m = 31
  91.                 CASE 11: m = 30
  92.                 CASE 12: m = 31
  93.             END SELECT
  94.         ELSE
  95.             SELECT CASE month
  96.                 CASE 1: m = 31
  97.                 CASE 2: m = 29
  98.                 CASE 3: m = 31
  99.                 CASE 4: m = 30
  100.                 CASE 5: m = 31
  101.                 CASE 6: m = 30
  102.                 CASE 7: m = 31
  103.                 CASE 8: m = 31
  104.                 CASE 9: m = 30
  105.                 CASE 10: m = 31
  106.                 CASE 11: m = 30
  107.                 CASE 12: m = 31
  108.             END SELECT
  109.         END IF
  110.         oldm = om
  111.         om = om + m
  112.         IF om >= NrOfTheDayInYear AND oldm < NrOfTheDayInYear THEN EXIT FOR
  113.     NEXT
  114.     day = NrOfTheDayInYear - om + m
  115.     day$ = STR$(day): IF LEN(day$) < 3 THEN day$ = "0" + LTRIM$(day$)
  116.     month$ = STR$(month): IF LEN(month$) < 3 THEN month$ = "0" + LTRIM$(month$)
  117.  
  118.     GETDATE$ = LTRIM$(STR$(y)) + "-" + LTRIM$(month$) + "-" + LTRIM$(day$)
  119.  
  120.  
  121.  
  122.  
  123. FUNCTION ISLEAPYEAR (year)
  124.     IF year MOD 4 = 0 AND year MOD 100 THEN ISLEAPYEAR = 1
  125.     IF year MOD 100 = 0 AND year MOD 400 = 0 THEN ISLEAPYEAR = 1
  126.  
  127. FUNCTION GETDAYNAME$ (year, mmonth, day) 'otestovano brutalne, fuguje skutecne spravne!
  128.     DIM om AS LONG, m AS LONG, days AS LONG
  129.     days = day
  130.     FOR yyr = 1 TO year
  131.         IF yyr = year THEN monthend = mmonth ELSE monthend = 12
  132.         FOR mont = 1 TO monthend
  133.             IF ISLEAPYEAR(yyr) = 0 THEN
  134.                 SELECT CASE mont
  135.                     CASE 1: m = 31
  136.                     CASE 2: m = 28
  137.                     CASE 3: m = 31
  138.                     CASE 4: m = 30
  139.                     CASE 5: m = 31
  140.                     CASE 6: m = 30
  141.                     CASE 7: m = 31
  142.                     CASE 8: m = 31
  143.                     CASE 9: m = 30
  144.                     CASE 10: m = 31
  145.                     CASE 11: m = 30
  146.                     CASE 12: m = 31
  147.                 END SELECT
  148.             ELSE
  149.                 SELECT CASE mont
  150.                     CASE 1: m = 31
  151.                     CASE 2: m = 29
  152.                     CASE 3: m = 31
  153.                     CASE 4: m = 30
  154.                     CASE 5: m = 31
  155.                     CASE 6: m = 30
  156.                     CASE 7: m = 31
  157.                     CASE 8: m = 31
  158.                     CASE 9: m = 30
  159.                     CASE 10: m = 31
  160.                     CASE 11: m = 30
  161.                     CASE 12: m = 31
  162.                 END SELECT
  163.             END IF
  164.             om = m
  165.             days = days + m
  166.         NEXT
  167.     NEXT
  168.     days = days - m - 1
  169.     a = (days MOD 7)
  170.     RESTORE nms
  171.     FOR r = 0 TO a
  172.         READ GETDAYNAME$
  173.     NEXT
  174.     nms:
  175.     DATA Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday
  176.  
  177.  
  178. FUNCTION GetDay$ (mm, dd, yyyy) 'use 4 digit year
  179.     'From Zeller's congruence: https://en.wikipedia.org/wiki/Zeller%27s_congruence
  180.     IF mm < 3 THEN mm = mm + 12: yyyy = yyyy - 1
  181.     century = yyyy MOD 100
  182.     zerocentury = yyyy \ 100
  183.     result = (dd + INT(13 * (mm + 1) / 5) + century + INT(century / 4) + INT(zerocentury / 4) + 5 * zerocentury) MOD 7
  184.     SELECT CASE result
  185.         CASE 0: GetDay$ = "Saturday"
  186.         CASE 1: GetDay$ = "Sunday"
  187.         CASE 2: GetDay$ = "Monday"
  188.         CASE 3: GetDay$ = "Tuesday"
  189.         CASE 4: GetDay$ = "Wednesday"
  190.         CASE 5: GetDay$ = "Thursday"
  191.         CASE 6: GetDay$ = "Friday"
  192.     END SELECT
  193.  

According to my tests, everything should work properly.

 
Tuesday and Thursday list.JPG



SierraKen, nice work!
« Last Edit: January 08, 2020, 04:31:01 pm by Petr »

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: How to calculate the day of the week for 40 years into the future
« Reply #6 on: January 09, 2020, 06:37:18 am »
rcamp48,

please use this repaired source (is repaired program loop, functions are the same as in previous case), beacuse previous source work bad if is date calculated over new year. 

In this source is this bug repaired.

Code: QB64: [Select]
  1.  
  2. 'function GETDAYNAME parameters: YEAR, MONTH, DAY
  3. 'listing of Tuesdays and Thursdays for 40 years
  4. 'FUNCTION GETDAYNR is upgraded and must be copyed to your program for correct work!
  5.  
  6.  
  7. DIM SHARED VirtualYear
  8.  
  9. DIM D AS INTEGER, Mnth AS INTEGER, VirtualYear AS INTEGER
  10.  
  11.  
  12. INPUT "Insert DAY, MONTH, YEAR: "; D, Mnth, VirtualYear
  13. INPUT "How much days find"; total
  14. IF Mnth < 0 OR Mnth > 12 THEN PRINT "Invalid value for month": SLEEP 2: END
  15. IF D < 0 OR D > 31 THEN PRINT "Invalid value for day": SLEEP 2: END
  16.  
  17.  
  18.  
  19. 'this is repaired     ------------------------------------------------------------------------------------------
  20. FOR l = 1 TO total
  21.     D = D + 1
  22.  
  23.     today$ = ""
  24.     DO UNTIL today$ = "Thursday" OR today$ = "Tuesday"
  25.         today$ = GETDAYNAME(VirtualYear, Mnth, D)
  26.         D = D + 1
  27.  
  28.     LOOP
  29.     D = D - 1
  30.  
  31.     DAY = GETDAYNR(VirtualYear, Mnth, D)
  32.  
  33.     IF ISLEAPYEAR(VirtualYear) AND DAY > 366 THEN VirtualYear = VirtualYear + 1: DAY = DAY - 366: D = D - 366
  34.     IF ISLEAPYEAR(VirtualYear) = 0 AND DAY > 365 THEN VirtualYear = VirtualYear + 1: DAY = DAY - 365: D = D - 365
  35.  
  36.     realdate$ = GETDATE$(DAY, VirtualYear)
  37.  
  38.     PRINT "Next date is "; realdate$; " "; GETDAYNAME(VirtualYear, Mnth, D); ", Week:"; 1 + DAY \ 7
  39.     SLEEP
  40. 'this is repaired     ------------------------------------------------------------------------------------------
  41.  
  42.  
  43.  
  44. FUNCTION GETDAYNR (y, mn, d) 'insert year, month and day and function calculate which day in year it is
  45.     FOR month = 1 TO mn
  46.         IF ISLEAPYEAR(y) = 0 THEN
  47.             SELECT CASE month
  48.                 CASE 1: m = 31
  49.                 CASE 2: m = 28
  50.                 CASE 3: m = 31
  51.                 CASE 4: m = 30
  52.                 CASE 5: m = 31
  53.                 CASE 6: m = 30
  54.                 CASE 7: m = 31
  55.                 CASE 8: m = 31
  56.                 CASE 9: m = 30
  57.                 CASE 10: m = 31
  58.                 CASE 11: m = 30
  59.                 CASE 12: m = 31
  60.             END SELECT
  61.         ELSE
  62.             SELECT CASE month
  63.                 CASE 1: m = 31
  64.                 CASE 2: m = 29
  65.                 CASE 3: m = 31
  66.                 CASE 4: m = 30
  67.                 CASE 5: m = 31
  68.                 CASE 6: m = 30
  69.                 CASE 7: m = 31
  70.                 CASE 8: m = 31
  71.                 CASE 9: m = 30
  72.                 CASE 10: m = 31
  73.                 CASE 11: m = 30
  74.                 CASE 12: m = 31
  75.             END SELECT
  76.         END IF
  77.         GETDAYNR = GETDAYNR + m
  78.     NEXT
  79.     GETDAYNR = GETDAYNR - (m - d)
  80.  
  81. FUNCTION __GETDAY
  82.     __GETDAY = VAL(MID$(DATE$, 4, 2))
  83.  
  84.  
  85. FUNCTION GETDATE$ (NrOfTheDayInYear, y) 'return date 'YYYYMMDD in year y
  86.     FOR month = 1 TO 12
  87.         IF ISLEAPYEAR(y) = 0 THEN
  88.             SELECT CASE month
  89.                 CASE 1: m = 31
  90.                 CASE 2: m = 28
  91.                 CASE 3: m = 31
  92.                 CASE 4: m = 30
  93.                 CASE 5: m = 31
  94.                 CASE 6: m = 30
  95.                 CASE 7: m = 31
  96.                 CASE 8: m = 31
  97.                 CASE 9: m = 30
  98.                 CASE 10: m = 31
  99.                 CASE 11: m = 30
  100.                 CASE 12: m = 31
  101.             END SELECT
  102.         ELSE
  103.             SELECT CASE month
  104.                 CASE 1: m = 31
  105.                 CASE 2: m = 29
  106.                 CASE 3: m = 31
  107.                 CASE 4: m = 30
  108.                 CASE 5: m = 31
  109.                 CASE 6: m = 30
  110.                 CASE 7: m = 31
  111.                 CASE 8: m = 31
  112.                 CASE 9: m = 30
  113.                 CASE 10: m = 31
  114.                 CASE 11: m = 30
  115.                 CASE 12: m = 31
  116.             END SELECT
  117.         END IF
  118.         oldm = om
  119.         om = om + m
  120.         IF om >= NrOfTheDayInYear AND oldm < NrOfTheDayInYear THEN EXIT FOR
  121.     NEXT
  122.     day = NrOfTheDayInYear - om + m
  123.     day$ = STR$(day): IF LEN(day$) < 3 THEN day$ = "0" + LTRIM$(day$)
  124.     month$ = STR$(month): IF LEN(month$) < 3 THEN month$ = "0" + LTRIM$(month$)
  125.  
  126.     GETDATE$ = LTRIM$(STR$(y)) + "-" + LTRIM$(month$) + "-" + LTRIM$(day$)
  127.  
  128.  
  129.  
  130.  
  131. FUNCTION ISLEAPYEAR (year)
  132.     IF year MOD 4 = 0 AND year MOD 100 THEN ISLEAPYEAR = 1
  133.     IF year MOD 100 = 0 AND year MOD 400 = 0 THEN ISLEAPYEAR = 1
  134.  
  135. FUNCTION GETDAYNAME$ (year, mmonth, day) 'otestovano brutalne, fuguje skutecne spravne!
  136.     DIM om AS LONG, m AS LONG, days AS LONG
  137.     days = day
  138.     FOR yyr = 1 TO year
  139.         IF yyr = year THEN monthend = mmonth ELSE monthend = 12
  140.         FOR mont = 1 TO monthend
  141.             IF ISLEAPYEAR(yyr) = 0 THEN
  142.                 SELECT CASE mont
  143.                     CASE 1: m = 31
  144.                     CASE 2: m = 28
  145.                     CASE 3: m = 31
  146.                     CASE 4: m = 30
  147.                     CASE 5: m = 31
  148.                     CASE 6: m = 30
  149.                     CASE 7: m = 31
  150.                     CASE 8: m = 31
  151.                     CASE 9: m = 30
  152.                     CASE 10: m = 31
  153.                     CASE 11: m = 30
  154.                     CASE 12: m = 31
  155.                 END SELECT
  156.             ELSE
  157.                 SELECT CASE mont
  158.                     CASE 1: m = 31
  159.                     CASE 2: m = 29
  160.                     CASE 3: m = 31
  161.                     CASE 4: m = 30
  162.                     CASE 5: m = 31
  163.                     CASE 6: m = 30
  164.                     CASE 7: m = 31
  165.                     CASE 8: m = 31
  166.                     CASE 9: m = 30
  167.                     CASE 10: m = 31
  168.                     CASE 11: m = 30
  169.                     CASE 12: m = 31
  170.                 END SELECT
  171.             END IF
  172.             om = m
  173.             days = days + m
  174.         NEXT
  175.     NEXT
  176.     days = days - m - 1
  177.     a = (days MOD 7)
  178.     RESTORE nms
  179.     FOR r = 0 TO a
  180.         READ GETDAYNAME$
  181.     NEXT
  182.     nms:
  183.     DATA Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday
  184.  
  185.  
  186. FUNCTION GetDay$ (mm, dd, yyyy) 'use 4 digit year
  187.     'From Zeller's congruence: https://en.wikipedia.org/wiki/Zeller%27s_congruence
  188.     IF mm < 3 THEN mm = mm + 12: yyyy = yyyy - 1
  189.     century = yyyy MOD 100
  190.     zerocentury = yyyy \ 100
  191.     result = (dd + INT(13 * (mm + 1) / 5) + century + INT(century / 4) + INT(zerocentury / 4) + 5 * zerocentury) MOD 7
  192.     SELECT CASE result
  193.         CASE 0: GetDay$ = "Saturday"
  194.         CASE 1: GetDay$ = "Sunday"
  195.         CASE 2: GetDay$ = "Monday"
  196.         CASE 3: GetDay$ = "Tuesday"
  197.         CASE 4: GetDay$ = "Wednesday"
  198.         CASE 5: GetDay$ = "Thursday"
  199.         CASE 6: GetDay$ = "Friday"
  200.     END SELECT
  201.  

Offline rcamp48

  • Newbie
  • Posts: 62
    • View Profile
Re: How to calculate the day of the week for 40 years into the future
« Reply #7 on: January 10, 2020, 03:14:40 am »
Thank you very much Peter, I will try that code in my program, it is 99.99 percent done.... Russ
Russ Campbell
rcamp48@rogers.com
BBS Files Programmer

Offline rcamp48

  • Newbie
  • Posts: 62
    • View Profile
Re: How to calculate the day of the week for 40 years into the future
« Reply #8 on: January 11, 2020, 09:05:55 pm »
rcamp48,

please use this repaired source (is repaired program loop, functions are the same as in previous case), beacuse previous source work bad if is date calculated over new year. 

In this source is this bug repaired.

Code: QB64: [Select]
  1.  
  2. 'function GETDAYNAME parameters: YEAR, MONTH, DAY
  3. 'listing of Tuesdays and Thursdays for 40 years
  4. 'FUNCTION GETDAYNR is upgraded and must be copyed to your program for correct work!
  5.  
  6.  
  7. DIM SHARED VirtualYear
  8.  
  9. DIM D AS INTEGER, Mnth AS INTEGER, VirtualYear AS INTEGER
  10.  
  11.  
  12. INPUT "Insert DAY, MONTH, YEAR: "; D, Mnth, VirtualYear
  13. INPUT "How much days find"; total
  14. IF Mnth < 0 OR Mnth > 12 THEN PRINT "Invalid value for month": SLEEP 2: END
  15. IF D < 0 OR D > 31 THEN PRINT "Invalid value for day": SLEEP 2: END
  16.  
  17.  
  18.  
  19. 'this is repaired     ------------------------------------------------------------------------------------------
  20. FOR l = 1 TO total
  21.     D = D + 1
  22.  
  23.     today$ = ""
  24.     DO UNTIL today$ = "Thursday" OR today$ = "Tuesday"
  25.         today$ = GETDAYNAME(VirtualYear, Mnth, D)
  26.         D = D + 1
  27.  
  28.     LOOP
  29.     D = D - 1
  30.  
  31.     DAY = GETDAYNR(VirtualYear, Mnth, D)
  32.  
  33.     IF ISLEAPYEAR(VirtualYear) AND DAY > 366 THEN VirtualYear = VirtualYear + 1: DAY = DAY - 366: D = D - 366
  34.     IF ISLEAPYEAR(VirtualYear) = 0 AND DAY > 365 THEN VirtualYear = VirtualYear + 1: DAY = DAY - 365: D = D - 365
  35.  
  36.     realdate$ = GETDATE$(DAY, VirtualYear)
  37.  
  38.     PRINT "Next date is "; realdate$; " "; GETDAYNAME(VirtualYear, Mnth, D); ", Week:"; 1 + DAY \ 7
  39.     SLEEP
  40. 'this is repaired     ------------------------------------------------------------------------------------------
  41.  
  42.  
  43.  
  44. FUNCTION GETDAYNR (y, mn, d) 'insert year, month and day and function calculate which day in year it is
  45.     FOR month = 1 TO mn
  46.         IF ISLEAPYEAR(y) = 0 THEN
  47.             SELECT CASE month
  48.                 CASE 1: m = 31
  49.                 CASE 2: m = 28
  50.                 CASE 3: m = 31
  51.                 CASE 4: m = 30
  52.                 CASE 5: m = 31
  53.                 CASE 6: m = 30
  54.                 CASE 7: m = 31
  55.                 CASE 8: m = 31
  56.                 CASE 9: m = 30
  57.                 CASE 10: m = 31
  58.                 CASE 11: m = 30
  59.                 CASE 12: m = 31
  60.             END SELECT
  61.         ELSE
  62.             SELECT CASE month
  63.                 CASE 1: m = 31
  64.                 CASE 2: m = 29
  65.                 CASE 3: m = 31
  66.                 CASE 4: m = 30
  67.                 CASE 5: m = 31
  68.                 CASE 6: m = 30
  69.                 CASE 7: m = 31
  70.                 CASE 8: m = 31
  71.                 CASE 9: m = 30
  72.                 CASE 10: m = 31
  73.                 CASE 11: m = 30
  74.                 CASE 12: m = 31
  75.             END SELECT
  76.         END IF
  77.         GETDAYNR = GETDAYNR + m
  78.     NEXT
  79.     GETDAYNR = GETDAYNR - (m - d)
  80.  
  81. FUNCTION __GETDAY
  82.     __GETDAY = VAL(MID$(DATE$, 4, 2))
  83.  
  84.  
  85. FUNCTION GETDATE$ (NrOfTheDayInYear, y) 'return date 'YYYYMMDD in year y
  86.     FOR month = 1 TO 12
  87.         IF ISLEAPYEAR(y) = 0 THEN
  88.             SELECT CASE month
  89.                 CASE 1: m = 31
  90.                 CASE 2: m = 28
  91.                 CASE 3: m = 31
  92.                 CASE 4: m = 30
  93.                 CASE 5: m = 31
  94.                 CASE 6: m = 30
  95.                 CASE 7: m = 31
  96.                 CASE 8: m = 31
  97.                 CASE 9: m = 30
  98.                 CASE 10: m = 31
  99.                 CASE 11: m = 30
  100.                 CASE 12: m = 31
  101.             END SELECT
  102.         ELSE
  103.             SELECT CASE month
  104.                 CASE 1: m = 31
  105.                 CASE 2: m = 29
  106.                 CASE 3: m = 31
  107.                 CASE 4: m = 30
  108.                 CASE 5: m = 31
  109.                 CASE 6: m = 30
  110.                 CASE 7: m = 31
  111.                 CASE 8: m = 31
  112.                 CASE 9: m = 30
  113.                 CASE 10: m = 31
  114.                 CASE 11: m = 30
  115.                 CASE 12: m = 31
  116.             END SELECT
  117.         END IF
  118.         oldm = om
  119.         om = om + m
  120.         IF om >= NrOfTheDayInYear AND oldm < NrOfTheDayInYear THEN EXIT FOR
  121.     NEXT
  122.     day = NrOfTheDayInYear - om + m
  123.     day$ = STR$(day): IF LEN(day$) < 3 THEN day$ = "0" + LTRIM$(day$)
  124.     month$ = STR$(month): IF LEN(month$) < 3 THEN month$ = "0" + LTRIM$(month$)
  125.  
  126.     GETDATE$ = LTRIM$(STR$(y)) + "-" + LTRIM$(month$) + "-" + LTRIM$(day$)
  127.  
  128.  
  129.  
  130.  
  131. FUNCTION ISLEAPYEAR (year)
  132.     IF year MOD 4 = 0 AND year MOD 100 THEN ISLEAPYEAR = 1
  133.     IF year MOD 100 = 0 AND year MOD 400 = 0 THEN ISLEAPYEAR = 1
  134.  
  135. FUNCTION GETDAYNAME$ (year, mmonth, day) 'otestovano brutalne, fuguje skutecne spravne!
  136.     DIM om AS LONG, m AS LONG, days AS LONG
  137.     days = day
  138.     FOR yyr = 1 TO year
  139.         IF yyr = year THEN monthend = mmonth ELSE monthend = 12
  140.         FOR mont = 1 TO monthend
  141.             IF ISLEAPYEAR(yyr) = 0 THEN
  142.                 SELECT CASE mont
  143.                     CASE 1: m = 31
  144.                     CASE 2: m = 28
  145.                     CASE 3: m = 31
  146.                     CASE 4: m = 30
  147.                     CASE 5: m = 31
  148.                     CASE 6: m = 30
  149.                     CASE 7: m = 31
  150.                     CASE 8: m = 31
  151.                     CASE 9: m = 30
  152.                     CASE 10: m = 31
  153.                     CASE 11: m = 30
  154.                     CASE 12: m = 31
  155.                 END SELECT
  156.             ELSE
  157.                 SELECT CASE mont
  158.                     CASE 1: m = 31
  159.                     CASE 2: m = 29
  160.                     CASE 3: m = 31
  161.                     CASE 4: m = 30
  162.                     CASE 5: m = 31
  163.                     CASE 6: m = 30
  164.                     CASE 7: m = 31
  165.                     CASE 8: m = 31
  166.                     CASE 9: m = 30
  167.                     CASE 10: m = 31
  168.                     CASE 11: m = 30
  169.                     CASE 12: m = 31
  170.                 END SELECT
  171.             END IF
  172.             om = m
  173.             days = days + m
  174.         NEXT
  175.     NEXT
  176.     days = days - m - 1
  177.     a = (days MOD 7)
  178.     RESTORE nms
  179.     FOR r = 0 TO a
  180.         READ GETDAYNAME$
  181.     NEXT
  182.     nms:
  183.     DATA Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday
  184.  
  185.  
  186. FUNCTION GetDay$ (mm, dd, yyyy) 'use 4 digit year
  187.     'From Zeller's congruence: https://en.wikipedia.org/wiki/Zeller%27s_congruence
  188.     IF mm < 3 THEN mm = mm + 12: yyyy = yyyy - 1
  189.     century = yyyy MOD 100
  190.     zerocentury = yyyy \ 100
  191.     result = (dd + INT(13 * (mm + 1) / 5) + century + INT(century / 4) + INT(zerocentury / 4) + 5 * zerocentury) MOD 7
  192.     SELECT CASE result
  193.         CASE 0: GetDay$ = "Saturday"
  194.         CASE 1: GetDay$ = "Sunday"
  195.         CASE 2: GetDay$ = "Monday"
  196.         CASE 3: GetDay$ = "Tuesday"
  197.         CASE 4: GetDay$ = "Wednesday"
  198.         CASE 5: GetDay$ = "Thursday"
  199.         CASE 6: GetDay$ = "Friday"
  200.     END SELECT
  201.  

One problem Peter , I am using Tuesdays and Fridays , not Tuesdays and Thursdays.
I will change the variables in my main program so I am not using any that you are using in the program you gave me.

Russ

PS:
I can do a global replace of all variables that do not make sense to a programmer anyways to more meaningful variables
Russ Campbell
rcamp48@rogers.com
BBS Files Programmer

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: How to calculate the day of the week for 40 years into the future
« Reply #9 on: January 12, 2020, 12:47:17 pm »
Hi, feel free to modify the program according to your needs, I have no problem with it :) 

The simplest modification is to throw the main program into your own SUB, as I did here:

Code: QB64: [Select]
  1.  
  2. DIM SHARED VirtualYear
  3. DIM Day AS INTEGER, Month AS INTEGER, Year AS INTEGER, TotalDays AS INTEGER
  4.  
  5.  
  6.  
  7. INPUT "Insert DAY, MONTH, YEAR: "; Day, Month, Year
  8. INPUT "How much days find"; TotalDays
  9. IF Month < 0 OR Month > 12 THEN PRINT "Invalid value for month": SLEEP 2: END
  10. IF Day < 0 OR Day > 31 THEN PRINT "Invalid value for day": SLEEP 2: END
  11.  
  12. PrintDate Day, Month, Year, TotalDays
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20. SUB PrintDate (D, Mnth, VirtualYear, Total) 'this was my program loop
  21.     FOR l = 1 TO Total
  22.         D = D + 1
  23.         today$ = ""
  24.         DO UNTIL today$ = "Friday" OR today$ = "Tuesday"
  25.             today$ = GETDAYNAME(VirtualYear, Mnth, D)
  26.             D = D + 1
  27.         LOOP
  28.         D = D - 1
  29.         DAY = GETDAYNR(VirtualYear, Mnth, D)
  30.         IF ISLEAPYEAR(VirtualYear) AND DAY > 366 THEN VirtualYear = VirtualYear + 1: DAY = DAY - 366: D = D - 366
  31.         IF ISLEAPYEAR(VirtualYear) = 0 AND DAY > 365 THEN VirtualYear = VirtualYear + 1: DAY = DAY - 365: D = D - 365
  32.         realdate$ = GETDATE$(DAY, VirtualYear)
  33.         PRINT "Next date is "; realdate$; " "; today$; ", Week:"; 1 + DAY \ 7
  34.         SLEEP
  35.     NEXT
  36.  
  37. FUNCTION GETDAYNR (y, mn, d) 'insert year, month and day and function calculate which day in year it is
  38.     FOR month = 1 TO mn
  39.         IF ISLEAPYEAR(y) = 0 THEN
  40.             SELECT CASE month
  41.                 CASE 1: m = 31
  42.                 CASE 2: m = 28
  43.                 CASE 3: m = 31
  44.                 CASE 4: m = 30
  45.                 CASE 5: m = 31
  46.                 CASE 6: m = 30
  47.                 CASE 7: m = 31
  48.                 CASE 8: m = 31
  49.                 CASE 9: m = 30
  50.                 CASE 10: m = 31
  51.                 CASE 11: m = 30
  52.                 CASE 12: m = 31
  53.             END SELECT
  54.         ELSE
  55.             SELECT CASE month
  56.                 CASE 1: m = 31
  57.                 CASE 2: m = 29
  58.                 CASE 3: m = 31
  59.                 CASE 4: m = 30
  60.                 CASE 5: m = 31
  61.                 CASE 6: m = 30
  62.                 CASE 7: m = 31
  63.                 CASE 8: m = 31
  64.                 CASE 9: m = 30
  65.                 CASE 10: m = 31
  66.                 CASE 11: m = 30
  67.                 CASE 12: m = 31
  68.             END SELECT
  69.         END IF
  70.         GETDAYNR = GETDAYNR + m
  71.     NEXT
  72.     GETDAYNR = GETDAYNR - (m - d)
  73.  
  74. FUNCTION __GETDAY
  75.     __GETDAY = VAL(MID$(DATE$, 4, 2))
  76.  
  77.  
  78. FUNCTION GETDATE$ (NrOfTheDayInYear, y) 'return date 'YYYYMMDD in year y
  79.     FOR month = 1 TO 12
  80.         IF ISLEAPYEAR(y) = 0 THEN
  81.             SELECT CASE month
  82.                 CASE 1: m = 31
  83.                 CASE 2: m = 28
  84.                 CASE 3: m = 31
  85.                 CASE 4: m = 30
  86.                 CASE 5: m = 31
  87.                 CASE 6: m = 30
  88.                 CASE 7: m = 31
  89.                 CASE 8: m = 31
  90.                 CASE 9: m = 30
  91.                 CASE 10: m = 31
  92.                 CASE 11: m = 30
  93.                 CASE 12: m = 31
  94.             END SELECT
  95.         ELSE
  96.             SELECT CASE month
  97.                 CASE 1: m = 31
  98.                 CASE 2: m = 29
  99.                 CASE 3: m = 31
  100.                 CASE 4: m = 30
  101.                 CASE 5: m = 31
  102.                 CASE 6: m = 30
  103.                 CASE 7: m = 31
  104.                 CASE 8: m = 31
  105.                 CASE 9: m = 30
  106.                 CASE 10: m = 31
  107.                 CASE 11: m = 30
  108.                 CASE 12: m = 31
  109.             END SELECT
  110.         END IF
  111.         oldm = om
  112.         om = om + m
  113.         IF om >= NrOfTheDayInYear AND oldm < NrOfTheDayInYear THEN EXIT FOR
  114.     NEXT
  115.     day = NrOfTheDayInYear - om + m
  116.     day$ = STR$(day): IF LEN(day$) < 3 THEN day$ = "0" + LTRIM$(day$)
  117.     month$ = STR$(month): IF LEN(month$) < 3 THEN month$ = "0" + LTRIM$(month$)
  118.  
  119.     GETDATE$ = LTRIM$(STR$(y)) + "-" + LTRIM$(month$) + "-" + LTRIM$(day$)
  120.  
  121.  
  122.  
  123.  
  124. FUNCTION ISLEAPYEAR (year)
  125.     IF year MOD 4 = 0 AND year MOD 100 THEN ISLEAPYEAR = 1
  126.     IF year MOD 100 = 0 AND year MOD 400 = 0 THEN ISLEAPYEAR = 1
  127.  
  128. FUNCTION GETDAYNAME$ (year, mmonth, day) 'otestovano brutalne, fuguje skutecne spravne!
  129.     DIM om AS LONG, m AS LONG, days AS LONG
  130.     days = day
  131.     FOR yyr = 1 TO year
  132.         IF yyr = year THEN monthend = mmonth ELSE monthend = 12
  133.         FOR mont = 1 TO monthend
  134.             IF ISLEAPYEAR(yyr) = 0 THEN
  135.                 SELECT CASE mont
  136.                     CASE 1: m = 31
  137.                     CASE 2: m = 28
  138.                     CASE 3: m = 31
  139.                     CASE 4: m = 30
  140.                     CASE 5: m = 31
  141.                     CASE 6: m = 30
  142.                     CASE 7: m = 31
  143.                     CASE 8: m = 31
  144.                     CASE 9: m = 30
  145.                     CASE 10: m = 31
  146.                     CASE 11: m = 30
  147.                     CASE 12: m = 31
  148.                 END SELECT
  149.             ELSE
  150.                 SELECT CASE mont
  151.                     CASE 1: m = 31
  152.                     CASE 2: m = 29
  153.                     CASE 3: m = 31
  154.                     CASE 4: m = 30
  155.                     CASE 5: m = 31
  156.                     CASE 6: m = 30
  157.                     CASE 7: m = 31
  158.                     CASE 8: m = 31
  159.                     CASE 9: m = 30
  160.                     CASE 10: m = 31
  161.                     CASE 11: m = 30
  162.                     CASE 12: m = 31
  163.                 END SELECT
  164.             END IF
  165.             om = m
  166.             days = days + m
  167.         NEXT
  168.     NEXT
  169.     days = days - m - 1
  170.     a = (days MOD 7)
  171.     RESTORE nms
  172.     FOR r = 0 TO a
  173.         READ GETDAYNAME$
  174.     NEXT
  175.     nms:
  176.     DATA Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday
  177.  
« Last Edit: January 12, 2020, 01:09:13 pm by Petr »

Offline rcamp48

  • Newbie
  • Posts: 62
    • View Profile
Re: How to calculate the day of the week for 40 years into the future
« Reply #10 on: January 13, 2020, 04:19:20 pm »
Hi Peter: If you have the time can you look at my program and let me know why it does not change days as supposed to ???

I enclose the source code itself for the latest version: 

99 percent of the program works ok, for both Lotto Max and Lotto 649, I have the source cod for both.

Russ
Russ Campbell
rcamp48@rogers.com
BBS Files Programmer

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: How to calculate the day of the week for 40 years into the future
« Reply #11 on: January 14, 2020, 01:39:10 am »
Hi, which BAS fle in ZIP? I look in, when I'll come back.

Offline rcamp48

  • Newbie
  • Posts: 62
    • View Profile
Re: How to calculate the day of the week for 40 years into the future
« Reply #12 on: January 15, 2020, 12:32:29 pm »
Its the main lottery program, I am working on a universal lottery program, its code is here : the two main programs are enclosed (wip)

 

Hey Pete you need to run the Universal Lottery setup program...it will run the main program, I will be working on the convert programs this afternoon,they are for converting lottery lists from the internet into a format that my lottery programs need...

Russ
« Last Edit: January 15, 2020, 01:12:15 pm by rcamp48 »
Russ Campbell
rcamp48@rogers.com
BBS Files Programmer

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: How to calculate the day of the week for 40 years into the future
« Reply #13 on: January 15, 2020, 12:44:21 pm »
Its the main lottery program, I am working on a universal lottery program, its code is here : the two main programs are enclosed (wip)

  
  [ Invalid Attachment ]  
  [ Invalid Attachment ]  
  [ Invalid Attachment ]  
  [ Invalid Attachment ]  
  [ Invalid Attachment ]  

That might get it going...going for lunch.
Russ

Might want to zip it into one archive, as I'm seeing:

kenoevening.dat
dname.dat
setup.dat
reg.dat
  [ Invalid Attachment ] 
  [ Invalid Attachment ] 
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline rcamp48

  • Newbie
  • Posts: 62
    • View Profile
Re: How to calculate the day of the week for 40 years into the future
« Reply #14 on: January 15, 2020, 01:08:19 pm »
Done...
Russ
Russ Campbell
rcamp48@rogers.com
BBS Files Programmer