I have a batch file that looks like the following:
For /f "tokens=2-4 delims=/ " %a in ('date /t') do (set newdate=%c%a%b)
blat my_file_%newdate% -to test@email.com -f test_email.com
When I enter this two commands separately in a cmd window, it seems to work perfectly fine, but when placed into a batch file and ran manually, it does not work.
Open a command prompt window and run
for /?
. Output is the help for this command containing at top the information:Next I suggest to run
set /?
and read at least last page of output help listing the environment variableDATE
.So there is perhaps no need to run in a separate command process in background with
cmd.exe /C
the command linedate /T
as done by FOR with the posted command line, capture output of this command process, and process it line by line by FOR.Well, the format of date output by
date /T
or on using%DATE%
depends on Windows region setting. And it was not posted what is the date format on used machine with used account. But I suppose that following works a very little bit faster too.I suppose using only string substitution works also on your machine for your account with a date format
mm/DD/yyyy
ordddd, mm/DD/yyyy
:This last solution is some microseconds faster than the others.
There is also a region independent solution as explained in detail for example by the answer on %date% produces different result in batch file when run from Scheduled Tasks in Server 2016. But region independent solution using WMIC is really much slower in comparison to using dynamic environment variable
DATE
.Batch variable need to have %% instead of only one
It appears you are looking for the output to be YYMMDD, if so try this: