I have created a scheduled task in Windows that consists of running a batch script. The problem is that this task has to be scheduled every 1st day of the month except for weekends.
For example, for the month of May, this task should run on May 02nd.
As I can't do it via the task scheduler, my idea is to schedule the execution task every day and add a condition checking that the execution day is the 1st day of the month excluding weekends.
This script would be of the following form :
if today = firstday
C:/MyExec/popo.exe arg1 arg2
Can you help me to write this script please?
Thank you in advance.
This version is language-independent, excepted for optional display, and doesn't require lock files.
I've put comments inside the batch itself, feel free to ask for precisions if needed. I've tested it for March and May 2022, it works and doesn't trigger the command more than one time per month.
The "day of week" formula comes from here: Mathematical curiosities / Find the day of the week with a given date (in French).
I took also Gerhard's trick for obtaining a fixed date format quickly through Powershell. It could also have been done with an embedded VBS script, since this language natively have the
Weekday
function, but it may have been quite unreadable to add a temporary script generation within the batch itself.