0

Using the ported Linux command date, you can get the date from the current date minus X days. I am trying to loop 1-30 days which will generate dates, then use those dates in a findstr. It seems that the loops work by themselves but when combined the inner for loop does not use the value X and date does not getr set. Anybody know what I'm doing wrong???!

    for /L %%x in (1,1,%SEARCHDAYS%) DO (
    set date1=
    for /f "delims=" %%a in ('date.exe --date "Now -%%x days" +%%-m/%%-d/') do @set date1=%%a
    echo "%date1%"

    findstr /c:"%date1%" file.txt
    )
    )

1 Answer 1

2

Have you tried SETLOCAL ENABLEDELAYEDEXPANSION, and then using "!" around the variables instead of "%"?

Sign up to request clarification or add additional context in comments.

3 Comments

I get c:\IBMITCSI300\programs\date.exe: invalid date Now -!x! days'`
looking again I had disabledelayedexpansion, checking now'
Looks like that was the problem! Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.