To get your required output in the cmd.exe
window you don't need a cmd for-loop at all, just a single powershell one:
@"%__AppDir__%WindowsPowerShell\v1.0\powershell.exe" -NoProfile "for($i=0; $i -le 10; $i++){"(Get-Date).AddDays(-$i).ToString('START_DATE: yyyy/MM/dd HH:mm:ss')}"
@Pause
If you need to run it from a cmd for-loop, because you need to perform additional work on each line of output then you should, once again, allow powershell to perform most of the heavy lifting:
@For /F Delims^= %%G In ('^"
"%__AppDir__%WindowsPowerShell\v1.0\powershell.exe" -NoProfile^
"for($i=0; $i -le 10; $i++){(Get-Date).AddDays(-$i).ToString(`"^
"'START_DATE: yyyy/MM/dd HH:mm:ss')}"^"')Do @Echo %%G
@Pause
This methodology could also be extended such that you can directly define the output as variables too, %Now[-1]%
, %Now[-2]%
, %Now[-3]%
etc. This would give you a simple way to get your required format dates based upon the number of days ago; for example:
@For /F Delims^= %%G In ('^"
"%__AppDir__%WindowsPowerShell\v1.0\powershell.exe" -NoProfile^
"for($i=1; $i -le 10; $i++){(Get-Date).AddDays(-$i).ToString(`"^
"\"Now[-$i]^=yyyy/MM/dd\")}"^"')Do @Set "%%G"
@Echo %Now[-6]%&Pause
The last line is obviously included just to show you what one of the defined variables would output.
Or based upon the simpler range method suggested by @lit in the comment section:
@For /F Delims^= %%G In ('^"
"%__AppDir__%WindowsPowerShell\v1.0\powershell.exe" -NoProfile^
"(0..-10)|%%{(Get-Date).AddDays($_).ToString(\"Now[$_]^=yyyy/MM/dd\")}"
^"')Do @Set "%%G"
@Echo %Now[0]%&Pause