1

How can we set timer job so that it will run on specific date of month?
For example, i want schedule timer job to run on 2nd and 28th day of month.
How can we do that?

1

I'm not sure if it's possible to configure a timer job in such a way to only fire on given dates, however, you could configure your timer job to run daily but include a date check as the first action in the job.

DateTime date = DateTime.Now;

if (date.Day.Equals(2) || date.Day.Equals(28))
{
    // It's either the 2nd or 28th of the month!
    // Put the rest of the code you want to run in here.
}

else
{
    // Do nothing - it's not the 2nd or 28th.
}

Here is a good walk through if you need more information on creating the timer job, taken from MSDN.

[Edit]

In reference to your comments on this answer. See this article from the sub heading Scheduling a Job to Run Each Day.

  • Hi scmc, your answer is very helpful and i really appreciate your help. If i need to configure my timer job on daily basis, should i need to set its interval to seconds(24hours)? – Ashish May 25 '15 at 14:43
  • Does it need to run just just once on the 2nd/28th? I.e. it does not recur throughout the whole day. – Stuart C May 25 '15 at 14:46
  • Just once on 2nd and 28th of month. i.e twice a month. – Ashish May 25 '15 at 14:48
  • I've editted my answer to include a link on how to schedule a timer job to run once per day. – Stuart C May 25 '15 at 14:52
1

There is no way to schedule timerjob by date. You should create daily timerjob and check if today is the 2nd or 28th day.

  • Thanks, and it will be very helpful if you can give me an example on how to schedule timer job on daily basis through coding. – Ashish May 25 '15 at 14:28
  • 1
    YourTimerJob tJob = new YourTimerJob(jobName, webApplication); tJob.Schedule = new SPDailySchedule(){ BeginHour = 4, EndHour = 5, }; And in the Execute method check: if (DateTime.Now.Day.Equals(2) || DateTime.Now.Day.Equals(28)) {your code here} – ScienceSoft team May 25 '15 at 14:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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