In Dyalog APL, you can make use of the interpreter's built-in DateToIDN
and IDNToDate
methods to convert to and from an International Day Number, and thus allow interger math.
You can conveniently package them as follows:
ToIDN ← {⊢ 2 ⎕NQ # 'DateToIDN' , ⍵}
ToDate ← {3 ⍴ 2 ⎕NQ # 'IDNToDate' , ⍵}
Try it online!
The ⊢
is to counter ⎕NQ
being shy, and the 3⍴
is to chop off the weekday number which is appended as a 4th element.
You can additionally define an operator which allows you to operate on dates seamlessly:
Datewise ← {ToDate (ToIDN ⍺) ⍺⍺ ⍵}
Try it online!
Finally, if you are not using Dyalog APL, or if you are interested in the actual formulas to determine the IDN, have a look at the days and date functions from the dfns workspace.