Understanding this catch command set start=%time: =0%

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
diverjer
Posts: 2
Joined: 21 Nov 2020 15:57

Understanding this catch command set start=%time: =0%

#1 Post by diverjer » 21 Nov 2020 16:56

I made up a batch file in Windows 10 to backup some of my data on USB and it works fine using Xcopy. I wanted to know how long it ran as I didn't set and watch, looking around I found this command"
set t2=%time: =0%. So I used replacing t2 with something more meaningful like start and end. set start=%time: =0%

My question is I don't understand what the : =0 after the time does? I open a cmd screen and entered echo %time: =0% or echo %time: =2% or just echo %time% and get the same format of time. Thought I would see a differences. Even though my batch file works fine and I get the time displayed just fine, I wonder what this : =0 does? I guess it comes from being an old computer programmer- long time retired. Use to program Assembly, COBOL, Fortran and sometimes even machine language or binary.

Squashman
Expert
Posts: 4206
Joined: 23 Dec 2011 13:59

Re: Understanding this catch command set start=%time: =0%

#2 Post by Squashman » 21 Nov 2020 18:23

Just use Robocopy. It will tell you how long it ran.

Your other option is to use Dave's JTIMESTAMP.

But to answer your question. A blank is getting replaced with a zero. So if it is 9 am in the morning the time will display as 09:00 instead of 9:00. Date and Time manipulation has been discussed ad nauseum on this forum. If you search and read all the links you will find a wealth of information. You would be better off calling out to WMIC or Powershell to get the time and date in a consistent format because the DATE and TIME variables do not display the same on everyone's computers because of local and regional settings.

diverjer
Posts: 2
Joined: 21 Nov 2020 15:57

Re: Understanding this catch command set start=%time: =0%

#3 Post by diverjer » 21 Nov 2020 22:59

Thanks, I get it, current time is 22:48 so I did an echo %time:2=9% and it displayed 99:48:58:95 The place I found and copied that example (set start=%time: =0%) of time must have wanted the leading zero to do some math calculations. I just wanted to display current time, so could have just used echo %time%. I will search around as you suggested.

Post Reply