Get File Safe Dates and Times |
At times you will need or wish to use date and time information in file or folder names (logs etc), this is one way:
@echo off for /F "tokens=1,2,3,4 delims=/ " %%i in ('date /T') do set YYYYMMDDDay=%%l-%%k-%%j (%%i) for /F "tokens=1,2 delims=:" %%i in ('time /T') do set hhmm=%%i_%%j echo YYYYMMDDDay: %YYYYMMDDDay% (In Australia anyway, we use DD/MM/YYYY) echo hhmm : %hhmm%
And this is another which uses the "String Replacement" tip:
echo DATE-SAFE "%date:/=-%" (date env var with "/" replaced by "-") echo TIME-SAFE "%time::=_%" (time env var with ":" replaced by "_")
You may also wish to have a look at the "Get Day, Month, and Year" section.