Getting the first day of the week of any week.

Hi all, this is a problem that's been troubling me for some time.

Let's say that I have the following date, "08/18/2021". I know that it falls on a wednesday, and I want to substract enough days in order to get "08/16/2021" as the result. Same for any other date in the same week, I'd like to automatically detect how many days have passed in the week so it always results in the Monday of that week.

My approach has been the following:

a!localVariables(
local!ctrlday: weekday(todate("08/18/2021")),
datetext(todate("08/18/2021") - day() * (local!ctrlday - 3), "yyyy/MM/dd"),
)

And it "works" for that example, but if I were to calculate "08/17/2021" and substract 2, it would end up with "08/15/2021".

Any ideas on how to make this behave properly?

Thank you in advance.

  Discussion posts and replies are publicly visible