create yesterday's date folder yyyy-mm-dd using .bat <p>I am attempting to create a prior date folder using the below script, and the problem is that it skips the month. To illustrate my point it ends up with <code>2016-2-</code>. Thus, any relevant feedback on this would be appreciated. </p> <p>Ps: Current date from my machine: <code>3/3/2016</code></p> <p>Best,</p> <pre><code>@echo off setlocal enabledelayedexpansion cls set vbs=%temp%\vbs.vbs &gt; %vbs% echo WScript.Echo DateAdd("d",-1,Date) for /f "tokens=* delims=" %%a in ('cscript //nologo %vbs%') do ( set newfold=%%a ) del %vbs% for /f "tokens=1-3* delims=/ " %%1 in ("%newfold%") do ( set month=%%2&amp;set date=%%3&amp;set year=%%4 md !date!-!month!-!year! echo New folder created = !date!-!month!-!year! ) </code></pre> <p><strong>EDIT:</strong> <code>VBScript</code> using the <code>Weekday()</code> function</p> <pre><code>@echo off setlocal EnableDelayedExpansion cls set vbs=%temp%\vbs.vbs &gt;%vbs% echo dateYesterday=DateAdd("d",-1,Date): wdayYesterday=Weekday(dateYesterday): If wdayYesterday=1 Then WScript.Echo DateAdd("d",-2,dateYesterday) Else If wdayYesterday=7 Then WScript.Echo DateAdd("d",-1,dateYesterday) Else WScript.Echo dateYesterday for /f "tokens=* delims=" %%a in ('cscript //nologo %vbs%') do ( set newfold=%%a ) echo dateYesterday = %newfold% ^(assumption: month/day/year^) del %vbs% for /f "tokens=1-3 delims=/ " %%1 in ("%newfold%") do ( set month=%%2 set day=%%1 set year=%%3 ) md %day%-%month%-%year% echo New folder created = %day%-%month%-%year% ^(day/month/year^) </code></pre>