Parsing Date in a Batch File
Today I was trying to generate a filename based on the current date in a
batch file. After doing some searching here is what I came up with:
@For /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @(
Set Month=%%A
Set Day=%%B
Set Year=%%C
)
@echo DAY = %Day%
@echo Month = %Month%
@echo Year = %Year%
This allows for me to format the date anyway I want. I didn't know that the
/F command of the For
loop could tokenize line output. Thats pretty cool, although there should be a
little better string support for batch
files.
Also posted on my
new blog.