Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
BAM Sample Programs
#34
(10-08-2024, 06:36 PM)TDarcos Wrote:
(02-17-2024, 08:22 PM)CharlieJV Wrote: Latest batch of programs: Added 2024-02
Your "Which weekday" program https://basicanywheremachine.neocities.o...ch_weekday has an error. Try the date 1-1-1800, which was a Wednesday. This program says it's Tuesday.

I have the same problem. I can never get any Zeller's congruence formulas to consistently produce correct results.

Code: (Select All)
Function GetWeekDay& (Day$) 'use MM/DD/YYYY format
    'From Zeller's congruence: https://en.wikipedia.org/wiki/Zeller%27s_congruence
    If CheckDayFormat(Day$) = 0 Then GetWeekDay = 0: Exit Function
    Dim As Long century, zerocentury, result
    Dim As Long MM, DD, YYYY
    MM = GetMonth(Day$): DD = GetDay(Day$): YYYY = GetYear(Day$)
    If MM < 3 Then MM = MM + 12: YYYY = YYYY - 1
    century = YYYY Mod 100
    zerocentury = YYYY \ 100
    result = (DD + Int(13 * (MM + 1) / 5) + century + Int(century / 4) + Int(zerocentury / 4) + 5 * zerocentury) Mod 7
    If result = 0 Then result = 7
    GetWeekDay& = result 'results are 1 to 7, from Sunday to Saturday
End Function

The above gives Wednesday as the proper result.  Use with the below for quick insertion of the weekday name:

Code: (Select All)
Function GetWeekDayName$ (Day$) 'use MM/DD/YYYY format
    Dim result As Long
    result = GetWeekDay(Day$)
    Select Case result
        Case 1: GetWeekDayName = "Sunday"
        Case 2: GetWeekDayName = "Monday"
        Case 3: GetWeekDayName = "Tuesday"
        Case 4: GetWeekDayName = "Wednesday"
        Case 5: GetWeekDayName = "Thursday"
        Case 6: GetWeekDayName = "Friday"
        Case 7: GetWeekDayName = "Saturday"
    End Select
End Function
Reply


Messages In This Thread
BAM Sample Programs - by CharlieJV - 09-12-2023, 05:01 AM
RE: BAM Sample Programs - by CharlieJV - 02-17-2024, 08:22 PM
RE: BAM Sample Programs - by TDarcos - 10-08-2024, 06:36 PM
RE: BAM Sample Programs - by SMcNeill - 10-08-2024, 06:45 PM
RE: BAM Sample Programs - by CharlieJV - 10-08-2024, 10:17 PM
RE: BAM Sample Programs - by bplus - 02-17-2024, 09:03 PM
RE: BAM Sample Programs - by CharlieJV - 02-17-2024, 09:07 PM
RE: BAM Sample Programs - by PhilOfPerth - 02-18-2024, 02:15 AM
RE: BAM Sample Programs - by CharlieJV - 02-18-2024, 06:53 AM
RE: BAM Sample Programs - by PhilOfPerth - 02-18-2024, 11:49 PM
RE: BAM Sample Programs - by CharlieJV - 02-19-2024, 02:00 AM
RE: BAM Sample Programs - by CharlieJV - 03-12-2024, 01:08 AM
RE: BAM Sample Programs - by Pete - 03-12-2024, 01:28 AM
RE: BAM Sample Programs - by CharlieJV - 03-12-2024, 12:25 PM
RE: BAM Sample Programs - by CharlieJV - 03-17-2024, 02:34 AM
RE: BAM Sample Programs - by CharlieJV - 03-17-2024, 04:43 AM
RE: BAM Sample Programs - by CharlieJV - 03-21-2024, 02:38 AM
RE: BAM Sample Programs - by CharlieJV - 04-20-2024, 08:45 PM
RE: BAM Sample Programs - by bplus - 04-20-2024, 08:58 PM
RE: BAM Sample Programs - by CharlieJV - 04-20-2024, 09:57 PM
RE: BAM Sample Programs - by CharlieJV - 05-07-2024, 02:21 AM
RE: BAM Sample Programs - by CharlieJV - 05-18-2024, 04:54 AM
RE: BAM Sample Programs - by CharlieJV - 05-29-2024, 11:09 PM
RE: BAM Sample Programs - by CharlieJV - 06-08-2024, 04:14 AM
RE: BAM Sample Programs - by CharlieJV - 07-02-2024, 04:30 AM
RE: BAM Sample Programs - by bplus - 07-02-2024, 02:08 PM
RE: BAM Sample Programs - by CharlieJV - 07-02-2024, 02:57 PM
RE: BAM Sample Programs - by Dav - 07-06-2024, 03:27 PM
RE: BAM Sample Programs - by CharlieJV - 07-06-2024, 05:40 PM
RE: BAM Sample Programs - by CharlieJV - 09-03-2024, 01:18 AM
RE: BAM Sample Programs - by Pete - 09-03-2024, 04:04 PM
RE: BAM Sample Programs - by CharlieJV - 09-03-2024, 08:39 PM
RE: BAM Sample Programs - by bplus - 09-03-2024, 04:57 PM
RE: BAM Sample Programs - by CharlieJV - 09-13-2024, 11:47 PM
RE: BAM Sample Programs - by CharlieJV - 10-08-2024, 01:28 AM
RE: BAM Sample Programs - by CharlieJV - 10-19-2024, 05:14 PM



Users browsing this thread: 6 Guest(s)