How do I include the date in a Windows Batch file?

I have used this many time in Windows batch files.

You can set any variable, in my example below called "thedate" to a substring of the computers date to produce only the numbers without any "/" in case this needs to be used in creating folder or file names.

For my example I would like to use a script to create a photos folder with the date in the name:

set thedate=%date:~-4,4%%date:~0,2%%date:~-7,2%

then you can show your output

echo %thedate%
 I then use

mkdir photos_%thedate%

to create a folder called "photos_20150727"














The above was created using Window 7.

Hope this help







Labels: , ,