Posted By

cappellin on 12/01/10


date format variable batch dos

Versions (?)

Get current date in format YYYYMMDD

 / Published in: DOS Batch

The code works if and only if your system is using English(United States) date format (i.e. "Web 05/11/2011"). If your systems is using English(United Kingdom) date format just replace %%B in the first and third rows with %%A.

  1. for /F "tokens=1* delims= " %%A in ('date /T') do set CDATE=%%B
  2. for /F "tokens=1,2 eol=/ delims=/ " %%A in ('date /T') do set mm=%%B
  3. for /F "tokens=1,2 delims=/ eol=/" %%A in ('echo %CDATE%') do set dd=%%B
  4. for /F "tokens=2,3 delims=/ " %%A in ('echo %CDATE%') do set yyyy=%%B
  5. set date=%yyyy%%mm%%dd%

Report this snippet  

You need to login to post a comment.