Chun ping Wang
Chun ping Wang

Reputation: 3929

Windows batch: date format variable not printing correctly

So i have this code.

FOR /F "tokens=*" %%A IN ('dateFormat +"%Y/%m/%d %T"') DO SET Now=%%A
CALL run_some_job "%Now%"

my output.

JOB_FILE_PATH>FOR /F "tokens=*" %A IN ('dateFormat +"m/T"
') DO SET Now=%A

JOB_FILE_PATH>SET Now=m/T

JOB_FILE_PATH>CALL run_some_job  m/T

I use the dateFormat tool from date.exe in this. http://unxutils.sourceforge.net/ to print date. If i do dateFormat +"%Y/%m/%d %T", than it works correctly.

Thanks

Upvotes: 1

Views: 442

Answers (1)

Arnout
Arnout

Reputation: 2790

You need to escape the percent signs in the date format argument:

FOR /F "tokens=*" %%A IN ('c:\utils\date +"%%Y/%%m/%%d %%T"') DO SET Now=%%A

Upvotes: 1

Related Questions