I first scripted YYYYMMDD.bat for How can I insure that a year, month, and day contain 4,2, and 2 digits, respectively?

I have scripted YYYYMMDD.bat to insure that the year, month, and day components of a date contain 4,2, and 2 digits, respectively, using a faster technique.

The syntax for using YYYYMMDD.bat is:

call yyyymmdd YY MM DD

Where:

YY is the name of the variable that contains the year.
MM is the name of the variable that contains the month.
DD is the name of the variable that contains the day.

Sample Usage

If you used UnivDate.bat to return the YY, MM, and DD environment variables, then:

call yyyymmdd yy mm dd

would insure that the year is 4 digits, and that the month and day are 2 digits, regardless of the short date (sShortDate) format.

NOTE: If you open a CMD prompt and type date and then press Enter, you can see that the second line of the output does contain a model of the date format that UnivDate.bat uses to name the year, month, and day environment variables.

NOTE: If after calling YYYYMMDD.bat, you wanted the year environment variable to contain the last 2 digits of the 4 digit year, use a command similar to:

<b>set YY=%YY:~-2%</b> YYYYMMDD.bat contains:
@echo off
if \{%3\}==\{\} @echo YYYYMMDD YYYY MM DD&goto :EOF
setlocal
call set YY=20%%%1%%
call set MM=0%%%2%%
call set DD=0%%%3%%
set YY=%YY:~-4%
set MM=%MM:~-2%
set DD=%DD:~-2%
endlocal&set %1=%YY%&set %2=%MM%&set %3=%DD%