Aug 26

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.


:: 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%


1 comment

  1. Raul

    Great info! thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>