Let's say you want to use notepad.exe
to open a file dated today, e.g., 20200909.txt. In your batch file, run this:
notepad %date:~10,4%%date:~7,2%%date:~4,2%.txt
You can manipulate the date string to your preference by extracting a range of characters from the %date%
variable as done in my example. E.g., %date:~10,4%
extracts 4 characters from the %date%
variable, starting at character 10.
Run echo %date%
to see what the standard date string looks like so you can experiment with it. System settings can affect how the string gets formatted, so yours might have variations. Mine prints like this, giving me an abbreviated day of the week and then the MM/DD/YYYY format:
Thu 09/10/2020
You can also store the date string in a variable and use it at will, like this:
set mydate=%date:~10,4%%date:~7,2%%date:~4,2%
notepad %mydate%.txt
If you specifically want the day of the week (e.g., Thursday), you can:
- Derive it from
%DATE:~0,3%
with some add'l logic not provided here
- Make do with the abbreviated date, e.g.
%DATE:~0,3%-Report.txt
for "Thu-Report.txt"
- Use any number of methods listed here.
But since your question left it somewhat open-ended what you mean by "date," I assume the general date string manipulation technique I discuss here can be adapted to your needs.