|
_$ (:DATE>WEEKDAY 1899 12 31)
"Sunday"
_$ (:DATE>WEEKDAY 1900 01 01)
"Sunday"
_$
[code](defun :DATE>WEEKDAY ( year month day / century-code month-code tmp x-nth year-code )
(defun :DXF (code elist) (cdr (assoc code elist ) ) )
(setq tmp (atoi (substr (itoa year) 1 2) ) )
(cond
( (= tmp 17) (setq century-code 4) )
( (= tmp 18) (setq century-code 2) )
( (= tmp 19) (setq century-code 0) )
( (= tmp 20) (setq century-code 6) )
( (= tmp 21) (setq century-code 4) )
)
(setq month-code (:DXF month '( (1 . 0)(2 . 3)(3 . 3)(4 . 6)(5 . 1)(6 . 4)(7 . 6)(8 . 2)(9 . 5)(10 . 0)(11 . 3)(12 . 5) ) ) )
(setq year-code (atoi (substr (itoa year) 3 2) ) )
(setq year-code (rem (+ year-code (/ year-code 4) ) 7) )
(setq x-nth (rem (+ year-code month-code century-code day) 7) )
;|
LEAP YEAR CODE -
The other thing to take into account is whether you are dealing with a leap year
EDIT: If the date is in a January or February of a leap year,
you have to subtract one from your total before the final step
https://artofmemory.com/blog/how-to-calculate-the-day-of-the-week/
https://www.calculator.net/day-of-the-week-calculator.html?today=02%2F02%2F1940&x=86&y=19
|;
(if (and (= (rem year 4) 0) (member month '(1 2) ) ) (setq x-nth (- x-nth 1) ) )
(if (= x-nth -1) (setq x-nth 6) )
(nth x-nth '("Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday") )
)
(defun C:K () (:DATE>WEEKDAY 2022 1 3 ) ) [/code] |
|