@echo off
cls
:: initialize constants
set StartDate=01-01-1996
set MONTHS=15
echo Show the last Mondays in the month,
echo for the %months% months starting %StartDate%
echo ==============================================================
set COUNT=1
:LOOPTOP
:: compare COUNT to MONTHS, exit loop if COUNT exceeds MONTHS
FDATE /F#comp /A%COUNT% /B%MONTHS% /vCOMP
if (%COMP%)==(GT) goto ENDLOOP
:: Use monthly arithmetic to get first day of next month
FDATE /Fm /N%COUNT% /A%StartDate% /Omm-dd-ccyy /VFdate
:: get the preceding Monday (/D2) -- the last Monday in this month
FDATE /Fw /D2 /N-1 /X /A%fdate% /P"%count% "
:: increment COUNT
FDATE /F#add /A%COUNT% /B1 /Vcount
GOTO LOOPTOP
:ENDLOOP
echo.
:endit
set StartDate=
set MONTHS=
set COUNT=
set COMP=
set FDATE=