When you just need the current HOUR, MINUTE, SECOND in a batch file.
set hr=%TIME: =0%
Here is how it works.
First off the hour. If you run echo %TIME% and it happens to be 7 AM, you’ll get ” 7″ Well that doesn’t work if you want the two digit format like “07”. To fix that I simply replaced a blank space with a zero, like so set hr=%TIME: =0%. If it is between the hours of 0-9 then it would look something like this “0 7”.
The Minute and Second share the same code, except it is already in two digit format so all it does is grabs the two digits and sets them to their respective vars.+1 this post if it helped you!