This is for current date, How do we use yesterday date ....?
@echo off
set YYYYMMDD=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%
set a=%YYYYMMDD%
echo %a%
This is for current date, How do we use yesterday date ....?
@echo off
set YYYYMMDD=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%
set a=%YYYYMMDD%
echo %a%
yesterday.bat
:you can use it like
Here's a one-liner with powershell which you most probably have installed:
and you can assign this to variable:
Something like this should do.
Obviously by increasing
set day=-1
to other numbers will deduct more days.Simply double click the batch or run from
cmd.exe
prompt.Try this shorter method (and the only pure-Batch solution in this topic):
If you want to know what happens here, remove the
@echo off
line and run the program...If you still have doubts about the method used, then you may do several tests over
+=
and!
operators, and how the parentheses work.Note that this solution does not work to subtract a number of days different than one. However, it is not difficult to insert the required adjustments to do that.