2

I have a context menu add-in which points to a batch file to create a new folder with the current date. I've been using it successfully on my Windows 10 machine but wanted to share it with my coworker. On his Windows 10 machine, the batch fails and shows a different value for curr_date. I've checked his time and region settings against mine but everything matches. I don't have much experience with troubleshooting this type of issue. Does anyone have any ideas?

Error is "The syntax of the command is incorrect."

set curr_date=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%
echo %curr_date%"
md %curr_date%NewProject
md %curr_date%NewProject\Deliverable

My machine curr_date prints:

"YYYYMMDD"

His machine curr_date prints:

"7/2"

Compo
  • 30,301
  • 4
  • 20
  • 32
diosity
  • 85
  • 5
  • 3
    don't use `%date%`, but an [independent way](https://stackoverflow.com/questions/7727114/batch-command-date-and-time-in-file-name/18024049#18024049) to get a date/time string. `%date%` is highly configurable and so insecure up to uselessness (as you noticed). – Stephan Aug 19 '20 at 17:04
  • 1
    Well, as already linked by @Stephan, you can see that there are locale dependancies. So to see the difference between your machine and his. run `echo %date%` on both devices. You'll notice why there is a difference in your results.. but these days `PowerShell` is the new batch, so you could just do `PowerShell Get-Date -format "yyyyMMdd"` – Gerhard Aug 19 '20 at 18:01

0 Answers0