Year Month Day Date Batch Script

Here’s a simple script that will give you today’s date in numeric format in three variables.  This has a bunch of uses, but I use it when I need to audit when a script was last run.  The script has been tested under Windows XP x86 and Windows 7 x64.  You may need to swap the varMM and varDD variables if you are using a version of Windows other than the U.S. version.

@ECHO OFF

:: Formatting the date into a YYYYMMDD format and setting it to the variable, varTodaysDate
SET varYYYY=%DATE:~10,4%
SET varMM=%DATE:~4,2%
SET varDD=%DATE:~7,2%
SET varTodaysDate=%varYYYY%%varMM%%varDD%

ECHO %varTodaysDate%

Share

1 comments

    • Raul on November 22, 2012 at 2:41 PM
    • Reply

    Great info! thanks!

Leave a Reply to Raul Cancel reply

Your email address will not be published.

*