3

I noticed you can only set the day of the month as a positive number 1..31 in the scheduled task GUI on Windows (Windows server 2003).

Is it possible to run a task only on the last day of the month? (This isn't a fixed day number, e.g. in February it could be the 28th or 29th day of the month, and in other months it may be the 30th or 31th.)

Related question, if I set a task to run on the 31th of every month, will it actually run in months with less days? Or will it run on the 1st of the next month in such cases?

4 Answers 4

4

Create the task using the schtasks command with the /mo LASTDAY option:

schtasks schedules commands and programs to run periodically or at a specific time. Adds and removes tasks from the schedule, starts and stops tasks on demand, and displays and changes scheduled tasks.

Syntax:

schtasks /create /tn TaskName /tr TaskRun /sc schedule [/mo modifier]
         [/d day] [/m month[,month...] [/i IdleTime] [/st StartTime] 
         [/sd StartDate] [/ed EndDate] [/s computer [/u 
         [domain\]user /p password]] 
         [/ru {[Domain\]User | "System"} [/rp Password]] /? 
0
3

You can do this in the user interface. When creating a trigger for a task, select monthly from the radio list. Then, for Months select <Select all months> and for Days select Last.

Selecting All Months

Selecting Last

1

Not sure if the GUI supports it natively, but you could get the task to kick off a vbs script or something before hand. Something like:

sub LastDateOfCurMonth() dim lstDateCurMonth, fstDateCurMonth, fstDateNxtMonth fstDateCurMonth="01/" & Month(date) & "/" & Year(Date) fstDateNxtMonth=DateAdd("m",1,fstDateCurMonth) lstDateCurMonth=DateAdd("d",-1,fstDateNxtMonth) wscript.echo "Last Date of Current Month is: " & lstDateCurMonth End Sub

1
  • The script I need to run exit immediately if tomorrow it is the same month as today, so this workaround would be trivial. (I've actually set it up now to just run the script every day; on anything but last day of month it's a no-op.)
    – Tobi
    Jun 25, 2009 at 10:05
1

Set up multiple schedules for the same task. One schedule for months that end on the 31st, one for months that end on the 30th, and another for the 28th. All you have to do is give each task a unique name.

1
  • Or, create a single task with multiple triggers.
    – Kade
    Apr 18, 2022 at 15:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .