This is some simple date functions and a crappy (sorry) demo to show how they can be used to create a calendar.
The original uses html to display the calendar together with a picture and links to notes and such. Hope it can be useful.

Code: Select all
;Date calculation functions:
Procedure DaysInMonth(Yr, Mn)
;Years 1562-3999, Mn 1-based
Dim N(12)
N(0) = 31: N(1) = 28: N(2) = 31: N(3) = 30: N(4) = 31: N(5) = 30
N(6) = 31: N(7) = 31: N(8) = 30: N(9) = 31: N(10) = 30: N(11) = 31
N(1) = N(1) + Bool( (Yr % 4 = 0) | (Yr % 100 = 0) & (Yr % 400 = 0))
ProcedureReturn N(Mn - 1)
EndProcedure
Procedure DayInWeek(Yr, Mn, Dy)
;Years 1562-3999, Mn/Dy 1-based, 1 is Sunday
N = Int((14 - Mn) / 12)
Y = Yr - N
M = Mn + 12 * N - 2
D = (Dy + Y + Int(Y / 4) - Int(Y / 100) + Int(Y / 400) + Int(31 * M / 12)) % 7
ProcedureReturn D + 1
EndProcedure
Procedure NumWeeks(Yr, Mn)
;Number of weeks (calendar rows) in a month, 4, 5 or 6
Days = DayInWeek(Yr, Mn, 1) - 1 + DaysInMonth(Yr, Mn)
If (Days % 7)
ProcedureReturn Int(Days / 7) + 1
Else
ProcedureReturn Int(Days / 7)
EndIf
EndProcedure
;Crappy demo:
Dim D.s(8)
D(0) = "": D(1) = "SUN": D(2) = "MON": D(3) = "TUE"
D(4) = "WED": D(5) = "THU": D(6) = "FRI": D(7) = "SAT"
Dim Dt(42)
OpenConsole()
ConsoleTitle("Calendar")
ConsoleColor(8, 15)
Repeat
ClearConsole()
Print("Year (1562 - 3999): "): Year = ValF(Input()): PrintN("")
Print("Month (1 - 12) : "): Month = ValF(Input()): PrintN("")
Days = NumWeeks(Year, Month)
First = DayInWeek(Year, Month, 1)
Last = First + DaysInMonth(Year, Month) - 1
Date = 1
For Day = First To Last
Dt(Day) = Date
Date + 1
Next Day
For Day = 1 To 7
ConsoleLocate(Day * 8, 4)
Print(D(Day))
Next Day
Weeks = NumWeeks(Year, Month)
For Week = 1 To Weeks
For Day = 1 To 7
Date = (Week - 1) * 7 + Day
ConsoleLocate(Day * 8, Week * 2 + 4)
If Dt(Date) <> 0
Print(Str(Dt(Date)))
Else
Print("")
EndIf
Next Day
Next Week
ConsoleLocate(1, 22)
Print("Press <Enter> To quit, Or C <Enter> To Continue...")
Key.s = UCase(Input())
Until Key <> "C"
CloseConsole()
End
;Demo end