Windows Batch File (.bat) to get current date in MMDDYYYY format.
This is a recipe I discovered while working on a few old skool dos batch files. This is a quick .bat file to create a folder based on the current date however, this sets it up in the MMDDYYYY format. Useful for those .bat scripters who need to use the current date variable in such a format.
Just copy and paste the text in quotes to a text file. Then rename file test.bat and run from command line to see (echo is on by default).
This can be used in a very powerful way, the FOR command can be reused and changed to query to see if a file exists and then if so create the folder, etc.
for now, lets start basic…
-
echo on
@REM Seamonkey’s quick date batch (MMDDYYYY format)
@REM Setups %date variable
@REM First parses month, day, and year into mm , dd, yyyy formats and then combines to be MMDDYYYY
FOR /F “TOKENS=1* DELIMS= ” %%A IN (’DATE/T’) DO SET CDATE=%%B
FOR /F “TOKENS=1,2 eol=/ DELIMS=/ ” %%A IN (’DATE/T’) DO SET mm=%%B
FOR /F “TOKENS=1,2 DELIMS=/ eol=/” %%A IN (’echo %CDATE%’) DO SET dd=%%B
FOR /F “TOKENS=2,3 DELIMS=/ ” %%A IN (’echo %CDATE%’) DO SET yyyy=%%B
SET date=%mm%%dd%%yyyy%
this does nothing but setup the %date variable to be todays date in MMDDYYYY format so it can be called later in the script, etc..
peace
seamonkey420





