Often you will create a windows batch file that runs on a periodic basis, and ideally you’d like it to reflect the current date when it does things like create files and folders.
I’ve seen some fairly arcane methods of retrieving and storing this information in variables through the years, but I think I’ve just found the most elegant solution.
To store today’s date in a variable with format yyyymmdd:
That’s it! This is pretty hard to find online. It seems to be usually part of the more complete expositions on variable expansion, and is described as String Substitutions or Substrings. Obviously you can change the offsets above to change your format, and also note the character position pointer is zero-based.