How can I get a filename YYYY.MM.DD_HH.MM.SS.7z? It should work with any regional settings!

The question is not duplicating 7-Zip CMD: Add current date to archive and include only the last modified folder in archive since I need seconds as well.



Well while this question is technically a different question, the answer is essentially the same as that other question:

Echo "%DATE:~-4%.%DATE:~4,2%.%DATE:~7,2%_%TIME:~0,2%.%TIME:~3,2%.%TIME:~6,2%

Since you specified that it must work with any regional settings though, that answer does not completely meet your needs. As far as I know, there is no way to meet your needs natively within cmd.exe. I would highly recommend doing this in powershell instead of cmd.



echo "%DATE:~10,4%.%DATE:~7,2%.%DATE:~4,2%_%TIME:~0,2%.%TIME:~3,2%.%TIME:~6,2%.7z"


  • Outputs: .01.5/_22.11.58.7z where I live - %Date returns the system date formatted according to the regional settings, so the position of day, month or year are not always the same. – Peter Hahndorf May 27 '12 at 20:58

@echo off

color 4f

mode 40,3

title Rename to date and time


:: Chunks gathered 'here & there'...

:: Batch rename 1 by 1 w. short delay,

:: to date + time w. milliseconds =>

:: no overwriting.


:: Western European regional settings:

:: OK. ANY regional settings: ?.. Might

:: require 'env. variables' replacement.




set "source=1_7z-orig-files-dir"

set "target=2_tmp"


if not exist "%target%\" md "%target%"

if not exist "%source%*.7z" goto END

for %%F in ("%source%*.7z") do (

set "file=%%~nxF"

move /y "%%F" "%target%" >nul

goto :break



:: %time:~-2,2% and :loop set

:: to 250 prevent overwriting:


set d=%date:~-4,4%-%date:~-7,2%-%date:~-10,2%

set d=%d: =_%

set t=%time:~-11,2%-%time:~-8,2%-%time:~-5,2%__%time:~-2,2%

set t=%t: =0%


ren "2_tmp*." "%d%__%t%."


set /a count = count + 1

if %count%==250 goto endloop

goto loop



move /y 2_tmp*.* .\


goto 7ZLOOP


  • Can you explain the above? :) – bertieb Jul 26 '18 at 6:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.