Find the nearest Date, given a TargetDate and Day of Week
Perl 6, 83 bytes
-&gt;$_,\w{~(Date.new(|m/(....)(..)(..)/)-3...*.day-of-week%7+1==w)[*-1]~~{S:g/&quot;-&quot;//}}

Try it
Expanded
-&gt;     # pointy block lambda
  $_,
  \w
{
  ~(  # turn into a Str

    Date.new( |m/(....)(..)(..)/ ) - 3 # three days earlier
    ...                                # generate a sequence
    *.day-of-week % 7 + 1 == w         # stop when the right day is found

  )[*-1]  # the last one

  ~~      # apply the following block

  {
    S:g/&quot;-&quot;//  # remove ｢-｣
  }
}