I am using the date command for a batch script.
I am wondering how to use command date to get yesterday date.
标签:
batch-file
相关问题
- xcopy include folder
- Batch file if string starts by
- Jenkins - cmd is not recognized
- String Manipulation with case sensitivity
- Writing an EXE output to a batch file
相关文章
- Extracting columns from text file using Perl one-l
- How can one batch file get the exit code of anothe
- How to make jenkins fail at a failing windows batc
- Problems using start-process to call other powersh
- Python utilizing multiple processors
- Why do all Pre-build or Post-build events in Visua
- Windows batch file - how to loop through files in
- Set variable in “if” block
There is a much cheaper way of doing this, exclusively in batch. I know its rough, but it worked for me.
Basically write yesterdays date into a text file like
yesterday.txt
. Then call it next time the process runs. Works for a process I have that runs once a day only.Then you can call yesterdays date as variable with
%yest%
.The main danger with the date variable is the locale sensitivity. If you have PowerShell available (it's a lot more common these days even in the big corporations) then you can use PowerShell to do the formatting and wrap it within a batch FOR statement.
The following PowerShell line will do the maths and format the date for you:-
You can then execute this via FOR to get it into a batch file variable (remembering to escape a whole bunch of characters with the hat ^ symbol, and using the backtick to avoid the embeded quotes):-
I'm sure someone with superior PowerShell and Batch programming skills can reduce the PowerShell command and/or the number of escaped characters to make it more readable/maintainable.
I found this script to work well
The results would look like:
Script taken from http://www.powercram.com/2010/07/get-yesterdays-date-in-ms-dos-batch.html