Tuesday, April 12, 2005

Convert Today's Date to YYYYMMDD In Batch File

Here is a simple script to convert today's date into yyyy-mm-dd format in batch file:
FOR /F "usebackq tokens=1,2,3,4 delims=/ " %%i IN (`date /t`) DO (
set yyyymmdd=%%l%%j%%k


Rikiller said...

Almost.. got k and j mixed up there.

FOR /F "usebackq tokens=1,2,3,4 delims=/ " %%i IN (`date /t`) DO (set yyyymmdd=%%l%%k%%j)

Corinna Lo said...

I think it depends on your Region and Language setting of your OS, date /t can be showing mm/dd/yyyy or dd/mm/yyyy.