FULLSCREEN CONTENTS Project Home Page
.EXAMPLE.....: 15 Find years when a given date fell on a given day of the week
.ALIAS.......: 15
.CATEGORY....: examples 
.CODE........:

[WHATDAY.BAT  This program has virtually no data validation, but if you are
careful to enter valid input data, it does the job.]

 @echo off
:: ----------------------------------------------------------------
:: This program calculates the years (within a specified range) that a
:: certain day of a certain month fell on a certain day of the week.
::
:: Note that we calculate and test both the day of the week and the
:: month.   This is because, for example, "February 29" of
:: a non-leapyear (an invalid date)
:: will be converted to the valid date of March 1.
:: So we want to be sure that in a given year, February 29 not only
:: occurred on the weekday in question, but also actually
:: occurred in February.
:: ----------------------------------------------------------------
 cls
 echo This program calculates the years (within a specified range) that a
 echo certain day of a certain month fell on a certain day of the week.
 echo.
 echo Please enter the day of the week that you want to search for.
 echo   1 = Sunday
 echo   2 = Monday
 echo   3 = Tuesday
 echo   4 = Wednesday
 echo   5 = Thursday
 echo   6 = Friday
 echo   7 = Saturday
 echo.
 fdate /fgetk /K1234567x /Q"Please press a number, or ESC to exit > " /vdow
 if (%Dow%)==(x) goto endit
 if (%Dow%)==(1) set DowName=Sunday
 if (%Dow%)==(2) set DowName=Monday
 if (%Dow%)==(3) set DowName=Tuesday
 if (%Dow%)==(4) set DowName=Wednesday
 if (%Dow%)==(5) set DowName=Thursday
 if (%Dow%)==(6) set DowName=Friday
 if (%Dow%)==(7) set DowName=Saturday
 echo You chose day of the week: %dowName%
 pause

 fdate /fget /Q"Please enter first year in year range > " /vBegYr
 fdate /fget /Q"Please enter last_ year in year range > " /vEndYr
 fdate /fget /Q"Please enter month number (1-12) > " /vMonNum
 fdate /fget /Q"Please enter day__ number (1-31) > " /vDayNum

 set Yr=%BegYr%
 fdate /fsubstr /a-2 /q00%MonNum% /vMonNum

 REM >whatday.txt
 cls
 echo Looking for %MonNum%/%DayNum% on %DowName%
 echo between %BegYr% and %EndYr%
 echo ----------------------------------------------
 echo Looking for %MonNum%/%DayNum% on %DowName% >>whatday.txt
 echo between %BegYr% and %EndYr% >>whatday.txt
 echo ---------------------------------------------- >>whatday.txt

 :LoopTop
   fdate /fsubstr /a-4 /q0000%yr% /vyr
   echo Testing %yr%
   fdate /ff /Idd-mm-ccyy /A%DayNum%-%MonNum%-%Yr% /v
   fdate /ff /Idd-mm-ccyy /A%DayNum%-%MonNum%-%Yr% /odow# /vdow#
   fdate /ff /Idd-mm-ccyy /A%DayNum%-%MonNum%-%Yr% /omm   /vmm

   if (%Dow#%)==(%Dow%) if (%MonNum%)==(%mm%) echo %fdate%
   if (%Dow#%)==(%Dow%) if (%MonNum%)==(%mm%) echo %fdate% >>Whatday.txt

   fdate /f#add  /A%yr% /B1 /vYr
   fdate /f#comp /A%yr% /B%EndYr% /v
   if (%fdate%)==(GT) goto LoopEnd
   goto LoopTop
 :LoopEnd

 cls
 type whatday.txt
 echo.
 echo This data has been written to file: Whatday.txt
 echo.
 :endit
 set Yr=
 set BegYr=
 set EndYr=
 set mm=
 set Dow=
 set Dow#=
 set DowName=
 set fdate=
 set MonNum=
 set DayNum=