Skip navigation

JSI Tip 0922. How do I schedule a job for the nth Monday (or Tuesday, Wednesday, etc..) of each month?

I have scripted a general purpose routine that you call in the batch job that you wish to schedule. You then schedule the job to run every week (example: /EVERY:Th). When your batch runs, JSInthDay will exit if "today" is not the nth occurance of the day, otherwise it will return control to the next statement.

Example: - To schedule a job for 01:00 on the 3rd Thursday of each month:

AT 01:00 /EVERY:Th cmd /c "<Drive:>\Folder\YourBatch.bat \[parameters\]"

In the beginning of your batch:

call JSInthDay 3

If the current Thursday is not the 3rd Thursday of the month, your batch will exit. If it is the 3rd Thursday, your batch will continue with the next statement.

The general syntax for calling JSInthDay is:

call JSInthDay N where N is the occurence number.

JSInthDay.bat uses JSIDateM and JSIToday. It contains:

@echo off
if not "%1"=="" goto doit
@echo Syntax: JSInthDay N
goto end
if "%1" LSS "1" goto syntax
if "%1" GTR "5" goto syntax
set /a nth=%1
call JSIToday
set nthy=%TDYY%
set nthm=%TDMM%
set nthd=%TDDD%
call JSIDatem %nthy% %nthm% %nthd% - 7
set nthm=%AMM%
set nthd=%ADD%
set /a nth=%nth% - 1
if %nth% EQU 0 goto same
if "%TDMM%" EQU "%AMM%" goto loop
if "%TDMM%" NEQ "%AMM%" goto end

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.