The main danger with a variable date is local sensitivity. If you have PowerShell (which is much more common these days even in large corporations), you can use PowerShell to format and transfer it to the batch FOR statement.
The next line of PowerShell will do the math and format the date for you: -
PowerShell $date = Get-Date; $date=$date.AddDays(-1); $date.ToString('yyyy-MM-dd')
Then you can do this via FOR to get it in the variable of the batch file (remembering to avoid the whole group of characters with the hat ^ symbol and use the return line to avoid the enclosed quotes): -
for /f "usebackq" %%i in (`PowerShell $date ^= Get-Date^; $date ^= $date.AddDays^(-1^)^; $date.ToString^('yyyy-MM-dd'^)`) do set YESTERDAY=%%i echo %YESTERDAY%
I'm sure someone with excellent PowerShell and Batch skills can reduce the PowerShell command and / or the number of escaped characters to make it more readable / supported.
source share