0

My goal is to create a new variable made of the variables %Year%, %Month% and %Day%. %Year% and %Day% are strings and %Month% is an integer.

This is what I have so far, but it doesn't work. How can I concatenate everything? I think the issue is the comma.

SET /A New_date = %Year%, %Month%, %Day%
Echo date:%New_date%
winter
  • 179
  • 1
  • 2
  • 11
  • 1
    Batch is sensitive to spaces in an ordinary string `SET` statement. `SET FLAG = N` sets a variable named "FLAG " to a value of " N" so your code is establishing a variable named `New_date ` and you are displaying a different variable, `New_date`. All batch variables are strings. Mathematical operations can be performed on variables whose values are (signed) numeric strings – Magoo May 26 '22 at 12:43
  • 1
    If you open a Command Prompt window, type `set /?` and press the `[ENTER]` key, you'll clearly see that the `/A` option is for performing arithmetic. As you aren't doing that, you don't want to use that option. ```Set "New_date=Year%, %Month%, %Day%"```. – Compo May 26 '22 at 12:44

1 Answers1

1

You don't need to use the /a option with Set here. That would be if you were doing numeric calculations.

Just use the following:

set "New_date=%Year%, %Month%, %Day%"
echo %New_date%

For more on Set

Qwerty
  • 131
  • 5