Okay, I've slept on it and woken with a refreshed set of grey cells.

Most importantly, I'm happy to say that I believe I can live with your suggestion. Consider the following program, which was inspired by a recent message in comp.lang.basic.misc:
Code: Select all
; DOW.PB
; Program to find the day of the week for a given Gregorian AD date.
Declare.l Days(Year.l, Month.l, Day.l)
Declare DateParts(JD.l, *Year.long, *Month.long, *Day.long)
Declare.s DoW(JD.l)
If OpenConsole()
Repeat
Print("Enter the Year (YYYY): ") : Y.l = Val(Input()) : PrintN("")
Print("Enter the Month (MM): ") : M.l = Val(Input()) : PrintN("")
Print("Enter the Day (DD): ") : D.l = Val(Input()) : PrintN("")
JD.l = Days(Y, M, D)
DateParts(JD, @Year, @Month, @Day)
Print(Str(Year) + "-" + Str(Month) + "-" + Str(Day) + " is/was a ")
Print(DoW(JD)) : PrintN("")
Print("Another? (y/n) ")
Repeat
K$ = Left(Inkey(),1)
Until K$ = "Y" Or K$ = "y" Or K$ = "N" Or K$ = "n"
Print(K$)
PrintN("") : PrintN("")
Until K$ = "N" Or K$ = "n"
EndIf
End
Procedure.l Days(Year.l, Month.l, Day.l)
; CONVERT DATE PARTS TO JULIAN DAY (SERIAL) NUMBER:
A.l = (14 - Month.l) / 12
Y.l = Year.l + 4800 - A.l
M.l = Month.l + (12 * A.l) - 3
D.l = Day.l + Int((153 * M.l + 2) / 5) + (365 * Y.l) + Int(Y.l / 4)
ProcedureReturn = D.l - Int(Y.l / 100) + Int(Y.l / 400) - 32045
EndProcedure
Procedure DateParts(JD.l, *Year.long, *Month.long, *Day.long)
; CONVERT JULIAN DAY (SERIAL) NUMBER TO DATE PARTS:
A.l = JD.l + 32045
B.l = (4 * (A + 36524)) / 146097 - 1
C.l = A.l - ((146097 * B) / 4)
D.l = ((4 * (C + 365)) / 1461) - 1
E.l = C - ((1461 * D) / 4)
M.l = ((5 * (E - 1)) + 2) / 153
*Year\l = ((100 * B) + D - 4800 + (M / 10))
*Month\l = M + (3 - (12 * (M / 10)))
*Day\l = E - (((153 * M) + 2) / 5)
EndProcedure
Procedure.s DoW(JD.l)
; COMPUTE DAY OF WEEK NUMBER:
DayOfWeek.l = (JD.l % 7)
; CONVERT DAY OF WEEK NUMBER TO DAY OF WEEK NAME:
N.s = "Monday Tuesday WednesdayThursday Friday Saturday Sunday"
ProcedureReturn = RTrim(Mid(N.s, (DayOfWeek.l * 9 + 1), 9))
EndProcedure
If you
Compile/Run this program and enter any AD date, you will be given the day of the week for that date. "So what?" you may ask, "...
PureBasic already has a DayOfWeek() function." "Sure it does, and it is convenient for all those people who are younger that 37 years of age who would like to know on which day of the week they were born," I would reply (probably with a little sarcasm in my voice), adding, "...and it cannot tell you that the First World War Armistace was signed on
Monday, 11 November, 1918." But I digress...
The purpose of the DateParts procedure is to correlate the user's input date. Try, for example, 2006-2-29 and 2005-14-32. The use of pointers here has resulted in compact, readable code, although it does seem to carry some baggage around with it, for example, having to remember to write .long or \l after variable names. I dare say that I'll quickly get used to that.
Thanks again to all of you -- including the latecomer,
netmaestro -- for your interest and help.
Here's to
reuseable,
economical,
fast,
efficient and
readable (REFER)
PureBasic code,
Cheers!
Lewis