Page 1 of 1

Simple concatenation fails

Posted: 18 Dec 2015 17:17
by karlik
Hello,

I just try to concatenate the following variables:
@echo off
FOR /F "tokens=1,2,3 delims=." %%a in ("%date%") do set yy=%%c& set mm=%%b & set dd=%%a
set /a lastyear=%yy%-1
set output=IS_%lastyear%

echo %output%

_________________________
Output:
IS_

Output should be IS_2014

Can somebody help me?

Re: Simple concatenation fails

Posted: 18 Dec 2015 21:07
by Meerkat
Fixed Code:

Code: Select all

@echo off
FOR /F "tokens=2,3,4 delims=/" %%a in ("%date: =/%") do set yy=%%c& set mm=%%b & set dd=%%a
set /a lastyear=%yy%-1
set output=IS_%lastyear%
echo %output%
Output:

Code: Select all

IS_2014


Have a look in the %date% variable:

Code: Select all

>echo %date%
Wed 12/16/2015
The delimiters here are [space] and Slashes. I used %date: =/% in IN so that the delimiter will only be slashes.

Code: Select all

>echo %date: =/%
Wed/12/16/2015

Meerkat

Re: Simple concatenation fails

Posted: 20 Dec 2015 15:39
by thefeduke
This is simpler, but works as well:

Code: Select all

FOR /F "tokens=2,3,4 delims=/ " %%a in ("%date%") do set yy=%%c& set mm=%%b & set dd=%%a
John A.

Re: Simple concatenation fails

Posted: 20 Dec 2015 18:13
by foxidrive
There are spaces there which will be a problem.