Software >> OS >> Windows >> Command Line >> How to create a variable from date and time commands

Batch file example ================== for /f "tokens=2-4 delims=/ " %%a in ('Date /T') do set Var1=%%c-%%a-%%b for /f "tokens=1-3 delims=: " %%a in ('TIME /T') do set Var2=%%a:%%b:%%c echo %Var1% echo %Var2% Note ==== To ensure 24 hour format for time, do a customisation of the Regional and Language Options from Control Panel alternatively ============= @echo off for /f "tokens=1-2 delims=." %%a in ('echo %time%') do set TimeA=%%a& set hsec=%%b for /f "tokens=1-3 delims=:" %%a in ('echo %TimeA%') do set hh=%%a& set mm=%%b& set ss=%%c echo %hh%%mm%%ss%%hsec%