udfGetWeekDayFromDate
int udfGetWeekDayFromDate (str)
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfGetWeekDayFromDate (strYmdHms) ; Using the Doomsday method.
strYmd = StrSub (strYmdHms, 1, 10) ; We need the date part only. Must be valid formatted "YYYY:MM:DD".
;If strYmd < "1582:10:15" Then Return 0 ; The Doomsday method is only valid for the Gregorian Calendar.
arrDC = Arrayize ("1,6,4,2", ",") ; Century Doomsdays.
strYear = ItemExtract (1, strYmdHms, ":")
intYear = Int (strYear)
intYY = intYear mod 100
intYM = intYY mod 12
intDY = (arrDC [intYear / 100 mod 4] + ((intYY / 12 + intYM + intYM / 4) mod 7) mod 7) ; Doomsday of the year.
intDays = 1 + TimeJulianDay (strYmd) - TimeJulianDay (strYear : ":01:01") ; 4-digit year is needed because of "WinBatch 2000 Automatic".
intDaysJanFeb = TimeJulianDay (strYear : ":03:01") - TimeJulianDay (strYear : ":01:01") ; The result is exclusive March 1st.
intJanZero = intDY + (7 - (intDaysJanFeb mod 7)) ; "January Day Zero".
intDay = ((intJanZero + (intDays mod 7)) mod 7) + 1 ; Add 1 to get number range 1..7 for Monday..Sunday.
Return intDay
;..........................................................................................................................................
; This UDF "udf" ...
;
; Parameter strYmdHms must be a valid DT-19 DateTime string of format "YYYY:MM:DD:HH:MM:SS"
; or can be abbreviated as a valid DT-10 Date String of format "YYYY:MM:DD".
;
; (c)Detlev Dalitz.20110218.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------

arrDayNames = Arrayize ("Sun,Mon,Tue,Wed,Thu,Fri,Sat,Sun", ",")


strYmdHms1 = "0000:01:01" ; Weekday=Saturday.
intWD1 = udfGetWeekDayFromDate (strYmdHms1)
strWD1 = arrDayNames[intWD1]

strYmdHms2 = "0030:01:27" ; Weekday=Sunday.
intWD2 = udfGetWeekDayFromDate (strYmdHms2)
strWD2 = arrDayNames[intWD2]

strYmdHms3 = "1954:12:01" ; Weekday=Wednesday.
intWD3 = udfGetWeekDayFromDate (strYmdHms3)
strWD3 = arrDayNames[intWD3]

strYmdHms4 = "1958:10:27" ; Weekday=Monday.
intWD4 = udfGetWeekDayFromDate (strYmdHms4)
strWD4 = arrDayNames[intWD4]

strYmdHms5 = "1966:02:17" ; Weekday=Thursday.
intWD5 = udfGetWeekDayFromDate (strYmdHms5)
strWD5 = arrDayNames[intWD5]

strYmdHms6 = "1993:10:05" ; Weekday=Tuesday.
intWD6 = udfGetWeekDayFromDate (strYmdHms6)
strWD6 = arrDayNames[intWD6]

strYmdHms7 = "2009:02:01" ; Weekday=Sunday.
intWD7 = udfGetWeekDayFromDate (strYmdHms7)
strWD7 = arrDayNames[intWD7]


Exit