Format Date In Batch File


/ Published in: DOS Batch
Save to your folder(s)

Nice script for formatting dates in a batch file without having the system locale settings impact your format


Copy this code and paste it in your HTML
  1. @echo off
  2. SETLOCAL EnableDelayedExpansion
  3.  
  4. for /f "skip=1 tokens=1-6 delims= " %%a in ('wmic path Win32_LocalTime Get Day^,Hour^,Minute^,Month^,Second^,Year /Format:table') do (
  5. IF NOT "%%~f"=="" (
  6. set /a FormattedDate=10000 * %%f + 100 * %%d + %%a
  7. set FormattedDate=!FormattedDate:~-2,2!/!FormattedDate:~-4,2!/!FormattedDate:~-6,2!
  8. )
  9. )
  10.  
  11. echo %FormattedDate%

URL: http://stackoverflow.com/questions/14427490/how-to-set-date-from-cmd-after-retrieving-it/14435810#14435810

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.