CMD specifying columns to save?

25 views Asked by At

I looked at a code by someone previously and saw them do code that went like:

    set Today=%DATE:~0,3%

And if the variable (%DATE%) was executed (echo %DATE%) it would come out with the first 3 letters of the date it was, this worked for other commands such as %TIME%, etc... But I was wondering if it was possible to specify what it takes instead of a first section, the reason I want this is cause I am attempting to make a logging system that logs with the times and date, though the %time% variable consists of colons, which can't be put as folder names,

Some attempts:

    set Today=%TIME:~0,2 ~4,5%

    set Today=%TIME:~0,2:4,5%

The list goes on, so to specify in more detail what I want, it is simply a way to take only the numbers of the %time% variable, or to remove the colons with a filtering method, if either are possible or you have a suggestion, please go ahead and tell me. Thanks for reading. :)

1

There are 1 answers

1
Dlanod Kcud On BEST ANSWER

You can't specify multiple regions from the variable but it is very easy to accomplish what you want:

set Today=%TIME:~0,2%%TIME:~3,2%

I assume you see the pattern...

Remember that DATE and TIME might look different on different locals so this may work fine on your local system but not if you go to a different system or change your local settings!

Reference: set /?