Skip to content

Instantly share code, notes, and snippets.

@santa4nt
Created November 3, 2010 00:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save santa4nt/660615 to your computer and use it in GitHub Desktop.
Save santa4nt/660615 to your computer and use it in GitHub Desktop.
Parse the output of `DATE /T` and return it in MMDDYYYY format.
@echo off
:: sample usage
call:getMMDDYYYY _DATE
echo _DATE: %_DATE%
goto:eof
:: -----------------------------------------------------------------------------
:: The "function"
:: -----------------------------------------------------------------------------
:getMMDDYYYY
setlocal
for /f "tokens=1* " %%A in ('date /t') do set _cdate=%%B
for /f "tokens=1,2 eol=/ delims=/ " %%A in ('date /t') do set _mm=%%B
for /f "tokens=1,2 eol=/ delims=/" %%A in ('echo %_cdate%') do set _dd=%%B
for /f "tokens=2,3 delims=/ " %%A in ('echo %_cdate%') do set _yyyy=%%B
( endlocal
set %~1=%_mm%%_dd%%_yyyy%
)
goto:eof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment