I’m linking the math for Datalog and Clojure respectively. But these are complicated mostly because of calculating the day of the week. For extracting the needed values out of the yyyymmdd format, quotient and modulo are enough.
yyyymmdd
quot
mod