Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>VBScript, PowerShell, or C# (I use CS-Script to run my C# scripts) would be <em>much</em> cleaner - but sometimes I enjoy a little batch file challenge.</p> <p>So - this is for 1 month from the current date and time, but it gives you the idea. To actually figure 30 days, I suspect you'd need about 50 lines of IF statements. Or, a single external EXE to calculate it for you.</p> <p>I think there's a cleaner way to use SET itself to split out the date parts, which would cut this down by about 3 lines - but I don't recall the syntax ATM.</p> <pre><code>Batch1 ECHO %DATE% &gt; start.txt Batch2 : Get start date FOR /F "tokens=1* delims= " %%i IN (start.txt) DO set startDate=%%j FOR /F "tokens=1,2 eol=/ delims=/ " %%i IN ('echo %startDate%') DO set startMonth=%%i FOR /F "tokens=1,2 delims=/ eol=/" %%i IN ('echo %startDate%') DO set startDay=%%j FOR /F "tokens=2,3 delims=/ " %%i IN ('echo %startDate%') DO set startYear=%%j : Get run month and day as YYYY-MM-DD SET /A runMonth=%startMonth% + 1 IF %runMonth% LEQ 10 SET runMonth=0%runMonth% SET runDay=%startDay% SET runYear=%startYear% SET runDate=%runYear%-%runMonth%-%runDay% : Get current month and day as YYYY-MM-DD FOR /F "tokens=1* delims= " %%i IN ('echo %DATE%') DO set nowDate=%%j FOR /F "tokens=1,2 eol=/ delims=/ " %%i IN ('echo %nowDate%') DO set nowMonth=%%i FOR /F "tokens=1,2 delims=/ eol=/" %%i IN ('echo %nowDate%') DO set nowDay=%%j FOR /F "tokens=2,3 delims=/ " %%i IN ('echo %nowDate%') DO set nowYear=%%j SET nowDate=%nowYear%-%nowMonth%-%nowDay% : Compare IF %nowDate% GEQ %runDate% ECHO Delete! </code></pre> <p>Note that this doesn't handle year changes appropriately (it'll delete on the year change).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload