Day of the Week

 BBS: Inland Empire Archive
Date: 08-08-92 (08:08)             Number: 118
From: BILL CAMPBELL                Refer#: NONE
  To: AL LAWRENCE                   Recvd: NO  
Subj: Day of the Week                Conf: (2) Quik_Bas
' Hi Al. I fiddled around with your question and came up with this.
' It's kinda clunky but, well, see the tagline for the editorial!

' This program can only work for years 1901 to 2099 because the
' years 1900 and 2100 are not leap years. I could fix this but -
' WHY ? I won't be here to take the fall for problems encouterred
' in 2100 !

usedate$ = DATE$
CLS

DIM days$(7)
days$(1) = "Sunday":     days$(2) = "Monday":    days$(3) = "Tuesday"
days$(4) = "Wednesday":  days$(5) = "Thursday":  days$(6) = "Friday"
days$(7) = "Saturday"

DIM month$(12, 2)
month$(1, 1) = "January":   month$(1, 2) = "31"
month$(2, 1) = "February": month$(2, 2) = "28"
month$(3, 1) = "March":     month$(3, 2) = "31"
month$(4, 1) = "April":     month$(4, 2) = "30"
month$(5, 1) = "May":       month$(5, 2) = "31"
month$(6, 1) = "June":      month$(6, 2) = "30"
month$(7, 1) = "July":      month$(7, 2) = "31"
month$(8, 1) = "August":    month$(8, 2) = "31"
month$(9, 1) = "September": month$(9, 2) = "30"
month$(10, 1) = "October":  month$(10, 2) = "31"
month$(11, 1) = "November": month$(11, 2) = "30"
month$(12, 1) = "December": month$(12, 2) = "31"

' The first day of the year can only fall on one of seven choices
' which will set the sequence for the rest of the year.
' Each of those choices may or may not fall in a leap year thus
' doubling your possible yeartypes to 14.

DIM DayYearStarted$(14)
' 1 = sunday and 7 = saturday as per the array days$
FOR startday = 1 TO 7
        DayYearStarted$(startday) = days$(startday)
        DayYearStarted$(startday + 7) = days$(startday)
NEXT startday

'1901 started on yeartype 3 and the repeating sequence for yeartypes is :
' 3 4 5 13 1 2 3 11 6 7 1 9 4 5 6 14 2 3 4 12 7 1 2 10 5 6 7 8

DIM yearsequence(28)

yearsequence(1) = 3     ' if year = 1901 then use yearsequence(1)
yearsequence(2) = 4     ' if year = 1902 then use yearsequence(2)
yearsequence(3) = 5     ' if year = 1903 then use yearsequence(3)
yearsequence(4) = 13
yearsequence(5) = 1:   yearsequence(6) = 2:   yearsequence(7) = 3
yearsequence(8) = 11:  yearsequence(9) = 6:   yearsequence(10) = 7
yearsequence(11) = 1:  yearsequence(12) = 9:  yearsequence(13) = 4
yearsequence(14) = 5:  yearsequence(15) = 6:  yearsequence(16) = 14
yearsequence(17) = 2:  yearsequence(18) = 3:  yearsequence(19) = 4
yearsequence(20) = 12: yearsequence(21) = 7:  yearsequence(22) = 1
yearsequence(23) = 2:  yearsequence(24) = 10: yearsequence(25) = 5
yearsequence(26) = 6:  yearsequence(27) = 7:  yearsequence(28) = 8

year = VAL(RIGHT$(usedate$, 4))    ' determine yeartype
IF year MOD 4 = 0 THEN leap = -1
year = year - 1900
whichyeartype = year MOD 28
PointerToDayYearStarted = yearsequence(whichyeartype)
startdayvalue = PointerToDayYearStarted
IF startdayvalue > 7 THEN startdayvalue = startdayvalue - 7
startday$ = DayYearStarted$(PointerToDayYearStarted)
PRINT "This year started on a "; startday$

' compute number of days this year
numofcompletemonths = VAL(MID$(usedate$, 4, 5)) - 1
FOR countmonths = 1 TO numofcompletemonths
        numofdays = numofdays + VAL(month$(countmonths, 2))
NEXT countmonths
numofdays = numofdays + VAL(LEFT$(dates$, 2))
IF leap THEN numofdays = numofdays + 1
PRINT "Number of days this year so far is "; numofdays

whatday = numofdays MOD 8
thisday$ = days$((whatday + startdayvalue) MOD 8)
thismonth$ = month$(VAL(MID$(usedate$, 4, 5)), 1)
calendardate$ = LEFT$(usedate$, 2)
thisyear$ = RIGHT$(usedate$, 4)
PRINT "Today is "; thisday$

PRINT "Today's date is "; usedate$
PRINT "Which translates to ";
PRINT thisday$ + " " + thismonth$ + " " + calendardate$ + ", " + thisyear$


... OFFLINE 1.24 * If it's stupid and it works then it isn't stupid

--- Maximus 2.00
 * Origin: Durham Systems (ONLINE!) (1:229/110)
Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET