Posted By

kidmizere on 05/16/14


Tagged

date format


Versions (?)

Format Date In Batch File


 / Published in: DOS Batch
 

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

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

  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%

Report this snippet  

You need to login to post a comment.