/////////////////////////////////////////////////////////////////// // // This task identifies which weekday of the month it is (i.e., // 1st/2nd/3rd/4th/5th Monday/Tuesday/.../Saturday/Sunday) and // whether it is the last occurrence of that day for the month // /////////////////////////////////////////////////////////////////// // // Variables used: // // %0 : Used to compute the occurrence count (dec %DAY% until < 7) // %1 : Used to compute the week of the month (1 - 5) // %2 : Week descriptor (cosmetic) // /////////////////////////////////////////////////////////////////// DEFINE %0 %DAY% DEFINE %1 1 // Calculate the week number WHILE %0>07 // Decrement the Day of the month by one week (7 days) DEFINE %0 %0-=07 // Increment the occurrence in the month for this weekday by 1 DEFINE %1 %1+=1 LOOP // Define the week number descriptor according to the previous loop calculation IF %1==1 // 1st occur DEFINE %2 1st ELSEIF %1==2 // 2nd occur DEFINE %2 2nd ELSEIF %1==3 // 3rd occur DEFINE %2 3rd ELSEIF %1==4 // 4th occur DEFINE %2 4th ELSE // must be 5th DEFINE %2 5th ENDIF // Echo the results of the calculation & test ECHO Today (%MONTH%/%DAY%) is the %2 %DAY_OF_WEEK% in %MONTH_NAME% // Set %1 to maximum possible days for this month less 7 (for last week) IF %MONTH%==02 // Feb = 28 DEFINE %1 21 ELSEIF %MONTH%==04 OR %MONTH%==06 OR %MONTH%==09 OR %MONTH%==11 // these = 30 DEFINE %1 23 ELSE // rest = 31 DEFINE %1 24 ENDIF // Check if last %DAY_OF%WEEK% for this month IF %DAY%>%1 THEN ECHO (Note: It is also the last %DAY_OF_WEEK% in %MONTH_NAME%)