I need to get the previous working day in the dos batch file, since the files for processing have a date in the file names in the yyyymmddand format ddmmmyy.
It seems, according to Dos, to get the date of the next day is quite difficult in a clean dos command.
So, I turned to calling powershell in dos. still i get here:
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=%%
doing this, yyyymmddand ddmmmyy- today's date, yyyymmddEODand ddmmmyyEOD- the day before.
However, what should I do if I need to get the previous “business day”?
During the working day the best solution would probably be Excel WorkDay function , WORKDAY(start_date, days, [holidays])but now, for the sake of simplicity, let's just Monday to Friday as a working day. So, if today is Tuesday, then the previous working day is Monday, and if today is Monday, then the previous working day is on the previous Friday.
Here's an example of how to get the “next business day” on Powershell Golf: the next business day , however, it seems to start under the powershell interface. I tried, but could not turn it into a dos batch file.