Windows 8 and 8.1 Forums

Inserting a Timestamp into a File Name

  1. #1

    Inserting a Timestamp into a File Name

    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 by Daddyman; 27 Feb 2015 at 01:51.

      My System SpecsSystem Spec

  2. #2

    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 System SpecsSystem Spec

Inserting a Timestamp into a File Name

Similar Threads
Thread Forum
PC sometimes freezes when inserting a DVD
Sometimes when I insert a blank DVD into my optical drive, Windows Explorer does not show that the disc is present in the drive. If I then double-click on the icon for the optical drive, Windows Explorer hangs. When it restarts, all I get is a completely blank desktop and a taskbar that has no...
General Support
Color change select file in file explorer , don't like Blu
Hi there , I've been struggling trying to find out how I can change the Selected File color , in File Explorer since I switched to Windows 8. Looks like it's now a setting in the registry under control panel - colors - and have to enter values manually ??? I am sick of the always...
General Support
BSOD inserting Flash disk, using Firefox error 0x0000007f
It started yesterday. When I got a Flash disk from my friend the computer displayed blue screen when I inserted it into a USB port. After the reboot the situation reoccured but then without the presence of the USB. Later it happened when I used my own Flash disk. And yet another time when I wasn't...
BSOD Crashes and Debugging
Inserting an entire 28 addresses on to one label sheet in
Microsoft Word 2010. What I wish to do is that in my job I sometimes have like 30 or less contacts at one time I need to make shipping labels for for customer surveys. My question is how can I insert these addresses from outlook automatically WHILE SHOWING THE COMPANY NAME. I know there is a...
Software and Apps
Inserting the serial number in an ISO
Hi With MDT 2013, Windows ADK and the Windows 8.1 Update 64 bit (multiple editions) MSDN ISO, how do I create an ISO that allows no more insert the serial number of the Core edition during the its installation? Thanks Bye
Installation & Setup
Inserting a music CD causes Windows 8.1 to freeze
NicDG asked on December 15, 2013 The title says it all. I installed Windows 8.1 this weekend and...
General Support
File History - Restore Previous File Versions in Windows 8
How to Restore Previous Versions of your Files with File History in Windows 8 and 8.1 File History is a new feature introduced in Windows 8 that automatically backs up files that are in your libraries, contacts (C:\Users\(user-name)\Contacts), Internet Explorer favorites...

Eight Forums Android App Eight Forums IOS App Follow us on Facebook