0

I'm trying to print the output value of a date variable in CMD

SET /a lastYear=%date:~6,4%-1 set lastDate=31/12/%lastYear% & echo %lastDate%

But echo prints %lastDate%

Someone knows why I can't see the value of the variable?

Regards

mmuniz
  • 145
  • 1
  • 2
  • 7
  • 5
    The value of variables are expanded before the line of code is executed. The echo needs to be on another line or you need to use delayed expansion. – Squashman May 05 '21 at 20:38
  • 1
    Also you missed an ampersand, it should also be `& set lastDate=…`. – Compo May 05 '21 at 23:42
  • 2
    As a side note, what about letting powershell help? `powershell -nop (get-date).addyears(-1).tostring('31/12/yyyy')` – Compo May 06 '21 at 00:26

0 Answers0