Solved Inserting a Timestamp into a File Name

Daddyman

Member
Member
Messages
78
I'm trying to insert a timestamp as part of a file name and I realized that there is something basic about a timestamp that I do not understand:

Assume the output for echo %time% is 16:13:07.91.

Why is echo %time:~3,2% equal to 13? Does the colon not count as a character? In %date% the slash (/) does count as a character.
 
Last edited:

My Computer

System One

  • OS
    Windows 8
Aha - got this one solved.

The 'trick' is that the first character on the left is in the zero-ith position, not the first position. If echo %time% is 16:13:07.91, the '1' in 16 is in the zero-ith position and the 6 is in the first position.

To see this, try echo %time:~0,1% and you'll find that the result is the first character in the current time.

Going back to my original question about the time 16:13:07.91: 1 is in the zero-ith position, 6 is in the first position, the colon [:] is in the second position and 1 is in the third position. That's why echo %time:~3,2% is equal to 13.

Think digital! In the digital world, 0 isn't 'nothing,' it's a unique number.

Now I understand why some people prefer to indicate the time and date in a batch file by counting backwards from the right instead of forwards from the left. No pesky '0' to confuse you.
 

My Computer

System One

  • OS
    Windows 8
Back
Top