Batch file create data parameter

Often I use a batch file to format folders or files based on the current time. This will set a variable that is the current date/time formatted as YYYYMMDD-HHMMSS:

@echo off

rem --------------------------------------------
rem ------- SET UP DATETIME STAMP VARIABLE -----
rem --------------------------------------------
SET HOUR=%time:~0,2%
SET dtStamp9=%date:~-4%%date:~4,2%%date:~7,2%-0%time:~1,1%%time:~3,2%%time:~6,2% 
SET dtStamp24=%date:~-4%%date:~4,2%%date:~7,2%-%time:~0,2%%time:~3,2%%time:~6,2%

if "%HOUR:~0,1%" == " " (SET dtStamp=%dtStamp9%) else (SET dtStamp=%dtStamp24%)

rem ECHO %dtStamp%
rem --------------------------------------------