Here's a solution that creates the previousday.vbs file on the fly, uses it and deletes it later.
Saves the result in the NewDate variable
This example calculates 1 day ago, but can easily calculate the date later by changing the value of the offset variable.
@echo off set Offset=1 echo d = date() - WScript.Arguments.Item(0) > earlierday.vbs echo wscript.echo year(d) * 10000 + month(d) * 100 + day(d) >> earlierday.vbs for /f %%a in ('cscript //nologo earlierday.vbs %Offset%') do set NewDate=%%a del earlierday.vbs echo %NewDate% pause
You can refine this a bit by using% temp% \ earlyday.vbs to create a file in the temporary user folder.
Paxdiablo credits , as this is a simple setup in his previous post.
EDIT: There's something with a loop here, close to what I really need to do. It will take 14 days from today and return that date. Then he will continue to return 7 days until he reaches 35 days ago.
@echo off SETLOCAL EnableDelayedExpansion set BackDaysFrom=14 Set BackDaysTo=35 Set BackDaysStep=7 echo d = date() - WScript.Arguments.Item(0) > earlierday.vbs echo wscript.echo year(d) * 10000 + month(d) * 100 + day(d) >> earlierday.vbs for /L %%i in (%BackDaysFrom%, %BackDaysStep%, %BackDaysTo%) do ( for /f %%a in ('cscript //nologo earlierday.vbs %%i') do set NewDate=%%a echo !NewDate! ) del earlierday.vbs pause
source share