Return to Snippet

Revision: 66501
at May 16, 2014 03:45 by kidmizere

Initial Code
@echo off
    SETLOCAL EnableDelayedExpansion

    for /f "skip=1 tokens=1-6 delims= " %%a in ('wmic path Win32_LocalTime Get Day^,Hour^,Minute^,Month^,Second^,Year /Format:table') do (
        IF NOT "%%~f"=="" (
            set /a FormattedDate=10000 * %%f + 100 * %%d + %%a
            set FormattedDate=!FormattedDate:~-2,2!/!FormattedDate:~-4,2!/!FormattedDate:~-6,2!

    echo %FormattedDate%

Initial URL

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

Initial Title
Format Date In Batch File

Initial Tags
date, format

Initial Language
DOS Batch