Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to schedule a job to run on the 25th of each month. If the 25th falls on a weekend I need the job scheduled on last Friday before the 25th. The Windows Task Scheduler doesn't have an option for this kind of task. Can anybody tell me what I should do?

share|improve this question
up vote 1 down vote accepted

Poisonbit's answer is basically correct. If the scheduling functions built-in to the Windows task scheduler can't provide the type of specific schedule you need, you'll need to work around the limitations yourself. His suggestion is to execute your job from a script that the task scheduler will run on a simple daily schedule. But the script will be smart enough to only execute the "real" job on the proper day. I've taken the liberty of providing a PowerShell based sample you could use.

$today = Get-Date
$d = $today.Day
$wd = $today.DayOfWeek

if ( ($d -eq 25 -and $wd -ne "Saturday" -and $wd -ne "Sunday") -or (($d -eq 23 -or $d -eq 24) -and $wd -eq "Friday") )
    "time to execute my job"

All it does it check the current date. If it's the 25th and not Saturday/Sunday or if it's Friday and the 23rd or 24th, it will print the "time to execute my job" message which you would replace with the command to actually execute your job.

*Updated with better logic thanks to Paul

share|improve this answer
Arf... I loosed the "current window scheduler"... thanks for catching that. – poisonbit Apr 8 '11 at 18:22

A wrapper that evaluates such conditions.

If you know shell scripting, you can make it using gnu date.

If you know Perl, try Time::Piece (in core since Perl 5.009).

Then call the wrapper from cron.daily, calculate a date is a light daily task for a machine.

share|improve this answer

Ryan Bolger has got it for the Friday condition...

If the 25th falls on a Monday through Thursday though, you'll still want to run the program on the 25th, so change his conditional to

if (($day -eq 25) -or ($weekday -eq "Friday" -and $day -ge 23 -and $day -le 25))

Note: I've never done PowerShell scripting, I'm just guessing on syntax from the code Ryan provided.

share|improve this answer
Hah, I knew I was going to miss some cases without explicit testing. I'll update my answer. =) – Ryan Bolger Apr 8 '11 at 21:41
Ryan has got it now. I'd up vote if I had enough rep, but I'm not usually on this site. – Paul Hanbury Apr 12 '11 at 3:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.