title: how to get previous working day in windows command (via powershell)
body: <p>I need to get the previous working day in a dos batch file, as the files to handle has the date in the filenames, under <code>yyyymmdd</code> and <code>ddmmmyy</code> format.</p>
  
  <p>It seems, according to <a href="https://stackoverflow.com/questions/15094772/dos-to-get-next-day-date">Dos to get next day date</a> , this is rather complex in pure dos command.</p>
  
  <p>So I turned to calling powershell in dos. so far I get till here:</p>
  
  <pre><code>FOR /f "usebackq" %%i IN (`PowerShell $date ^= Get-Date^; $date.ToString^('yyyyMMdd'^)`) DO SET yyyymmdd=%%i
  FOR /f "usebackq" %%i IN (`PowerShell $date ^= Get-Date^; $date.ToString^('ddMMMyy'^)`)  DO SET ddmmmyy=%%
  FOR /f "usebackq" %%i IN (`PowerShell $date ^= Get-Date^; $date^=$date.AddDays^(-1^)^; $date.ToString^('yyyyMMdd'^)`) DO SET yyyymmddEOD=%%i 
  FOR /f "usebackq" %%i IN (`PowerShell $date ^= Get-Date^; $date^=$date.AddDays^(-1^)^; $date.ToString^('ddMMMyy'^)`)  DO SET ddmmmyyEOD=%% 
  </code></pre>
  
  <p>by doing so, <code>yyyymmdd</code> and <code>ddmmmyy</code> is today's date, while <code>yyyymmddEOD</code> and <code>ddmmmyyEOD</code> is the day before.</p>
  
  <p>However, what shall I do, if i need to get the previous "working day"?</p>
  
  <p>By <em>working day</em>, the best solution would probably like <a href="https://support.office.com/en-us/article/WORKDAY-function-f764a5b7-05fc-4494-9486-60d494efbf33" rel="nofollow noreferrer">Excel WorkDay function</a>, <code>WORKDAY(start_date, days, [holidays])</code>, but for now, for the sake of simplicity, let's just take Monday to Friday as <em>Working Day</em>. So that if today is Tuesday, then the <em>previous working day</em> is Monday, while if today is Monday, then the <em>previous working day</em> is previous Friday.</p>
  
  <p>There's an example on how to get the "next working day" at <a href="https://stackoverflow.com/questions/1018873/powershell-golf-next-business-day">Powershell Golf: Next business day</a> , however, it seems run under powershell interface. I tried but did not succeed turn it into a dos batch file. </p>