Clicky

20241116

Date-time strings to use in filenames

The DATE command in a Windows command console shows the date which is not suited for filenames, because of spaces and slashes or, with other country/language settings, colons or other characters that are not allowed in filenames:

These commands (in a Batch script) creates date-time formatted strings, that can be used in filenames:

 
REM *** With Powershell...
for /f "usebackq" %%i in (`powershell -command get-date -format 'yyyyMMdd-HHmmss'`) do set psDateTime=%%i
set TimeStamp=%psDateTime%
echo %timeStamp%-filename.ext

REM *** With WMIC...
for /f %%i in ('wmic os get LocalDateTime /value ^| find "="') do set wmicDateTime=%%i
set TimeStamp=%wmicDateTime:~14,8%-%wmicDateTime:~22,6%
echo %timeStamp%-filename.ext 
 

Result:

 

 

No comments :

Post a Comment

Real Time Web Analytics