title: Subtracting 3 days from date
body: <p>I want to calculate a <code>reminderDate</code> by subtracting 3 days from it. However, if the resulting date</p>
  <ul>
  <li>falls on a Saturday or Sunday, it should give the date of the Friday</li>
  <li>falls on a Friday, it should give the date of Thursday</li>
  </ul>
  <p>For example</p>
  <pre><code>Exchange Date                             ReminderDate
  
  18.06.2020                -3 days =       15.06.2020 --&gt; OK, because Monday
  17.06.2020                -3 days =       14.06.2020 --&gt; Sunday, must be changed to 12.06.2020 
  16.06.2020                -3 days =       13.06.2020 --&gt; Saturday, must be changed to 12.06.2020 
  15.06.2020                -3 days =       11.06.2020 --&gt; Friday, must be changed to 11.06.2020
  </code></pre>
  <p>I tried something like this, but neither <code>.getDay()</code> nor <code>.day()</code> seem to work. And <code>dt</code> seems to give the date of today, and not the date of <code>exchange</code>.</p>
  <pre><code>var exchange = NWF$(&quot;#&quot; + varAustauschtermin).val(); // date like 18.06.2020
  console.log(&quot;Exchange: &quot; + exchange);
  var reminderDate = moment(exchange, &quot;DD.MM.YYYY&quot;).format(&quot;DD.MM.YYYY&quot;);
  var dt = new Date(reminderDate);
  // var reminderDate = moment(exchange, &quot;DD.MM.YYYY&quot;).subtract(3, 'days').format(&quot;DD.MM.YYYY&quot;);
  
  // console.log(&quot;reminderDate.day(): &quot; + reminderDate.day()); 
  // console.log(&quot;reminderDate.getDay(): &quot; + reminderDate.getDay());
  
  if(dt.getDay() == 6) { // Saturday
      console.log(&quot;Saturday&quot;);
      reminderDate = moment(exchange, &quot;DD.MM.YYYY&quot;).subtract(1, 'days').format(&quot;DD.MM.YYYY&quot;);
  } else if (dt.getDay() == 0) { // Sunday
      console.log(&quot;Sunday&quot;);
      reminderDate = moment(exchange, &quot;DD.MM.YYYY&quot;).subtract(2, 'days').format(&quot;DD.MM.YYYY&quot;);
  } else if (dt.getDay() == 5) { // Friday
      console.log(&quot;Friday&quot;);
      reminderDate = moment(exchange, &quot;DD.MM.YYYY&quot;).subtract(1, 'days').format(&quot;DD.MM.YYYY&quot;);
  } else {
      console.log(&quot;Weekday&quot;);
      reminderDate = moment(exchange, &quot;DD.MM.YYYY&quot;).subtract(3, 'days').format(&quot;DD.MM.YYYY&quot;);
  }
  console.log(&quot;Reminder Date: &quot; + reminderDate);
  </code></pre>
  <p>Any help is appreciated!</p>