Developer's Closet A place where I can put my PHP, SQL, Perl, JavaScript, and VBScript code.

25May/091
Output the Date in a Windows Batch Script

This simple script will output the date in the MMDDYYYY format. The script can be used to enhance other scripts, for log files, etc.

@echo off
@REM Setups %date variable
@REM First parses month, day, and year into mm , dd, yyyy formats and then combines to be MMDDYYYY
@REM The date variable will be in the MMDDYYYY format so it can be called later in the script

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%

@echo on
echo hello %date%
pause