1. Use string replacement to change all spaces in %tm% to zeroes. In fact there will only ever be one space, at the start, when the hour is 0 to 9.
@echo off
set t=%time%
set tm=%t:~0,2%%t:~3,2%%t:~6,2%
set tmzero=%tm: =0%
echo t = "%t%"
echo tm = "%tm%"
echo tmzero = "%tmzero%"
Output...
t = " 8:32:14.07"
tm = " 83214"
tmzero = "083214"
Alternatively...
2. Maybe you prefer to test if the first character (offset 0) of %tm% is a space, and if it is, make a new string composed of a zero character and the characters of %tm% from position 2 (offset 1) to the end
@echo off
set t=%time%
set tm=%t:~0,2%%t:~3,2%%t:~6,2%
if "%tm:~0,1%"==" " set tmzero=0%tm:~1%
echo t = "%t%"
echo tm = "%tm%"
echo tmzero = "%tmzero%"
Output...
t = " 8:41:39.75"
tm = " 84139"
tmzero = "084139"
Alain, since your name sounds like you are French or at least francophone. I would like to tell you that although I am rosbif de chez rosbif, I am a big fan of a French rock group called INDOCHINE. Have you heard of them?