
However, we can use it to create a directory (the folder) of the day, like with the command: MD %ClamVirDir%\%today% Our demo batch file is just printed this on the screen with ECHO command. In our example, we collected 27 th day of the 5 th month of the year 2016 in the string with value of 20160527. We just need to write other variables one behind other and the batch interpreter will collect (concatenate) their values in one unique string. We can do that with following command: set today=%year%%month%%day% We will now collect all three separated values together and then we can form forth variable TODAY. Eventually we have three new variables for every element of the today date. When we collect all this together, we will have :~7,2 as the marker for a beginning and the end of the selection. In our example it’s 2, as we need to extract just 7 th and 8 th character in the string. With second value we will indicate length of the substring. We will indicate position of first character with value of X. The x and y are number position and length. We can add :~x,y behind variable name, inside % signs, to tell the batch interpreter that we want just the part of the value, not whole variable value. It’s on 8 th character in the string and that’s position 7. Also, we counted position of that information. Now we need just part of this output (the date string) for out variable named DAY. In our first example we saw that we can display a current day with command ECHO %date% We will analyze further first line: set day=%date:~7,2% Main part of this batch is done in the first three lines beginning with the command SET. I made another batch file, named get_today_date.bat, which will demonstrate this operation. Now that we know what we need to extract, we can use this to write our batch file.

We don’t need to count manually positions. Those numbers under the date string will be the position counter. I changed short date format to display the date on the way more common to the Serbian local settings. Here is another example of the changed local settings.

When we run this batch file from the command prompt, we will see current date. Here is source of the check_date_format.bat file: off Those numbers will be used to mark a position of every number or the letter in the date string. I made a simple batch script that will just return the current date and under it write some numbers.
#Windows mass rename based on timestamp windows
I used all those scripts on the Windows XP, 2003 Server and later versions of the Microsoft Windows operating systems. With this method you will always have the same format of the current day or time, regardless the local regional settings.

(Update ) You can find the alternate way to read the current date and time values in this post. That’s the reason why we need to check this settings before we can use any batch file that utilize the date value. Therefore, our batch file will work fine with one settings and return useless information with other. The batch files can use special variable named DATE and which returns the current date in the local regional format.Īs we knew, the regional settings are different. We can use the value of current date (and also time) in the batch files, whenever we generating new files and folders. We can use, for example, the dates to distinguish the log files by the days. Using current date as part of the file or a folder (the directory) name is very useful.
