Scheduled Job - First Friday of each month

Martyna
Tera Contributor

Hi All,

I need to create a scheduled job for a task to generate on the first Friday of each month. I have seen similar question but I have one problem - I cannot specify the name of the day when the job will be running, only day numbers are available. Could you please advise me how to deal with it?

 

Thanks,

Martyna

2 ACCEPTED SOLUTIONS

Peter Bodelier
Giga Sage

Hi @Martyna 

 

You can use this:

 

answer = isFirstFridayOfMonth();
function isFirstFridayOfMonth() {
  // Get the current date
  const currentDate = new Date();

  // Get the first day of the month
  const firstDayOfMonth = new Date(currentDate.getFullYear(), currentDate.getMonth(), 1);

  // Check if the current day is a Friday
  const isFriday = currentDate.getDay() === 5;

  // Check if the current day is the first Friday of the month
  const isFirstFridayOfMonth = isFriday && firstDayOfMonth.getDay() === 5;

  return isFirstFridayOfMonth;
}

 


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

View solution in original post

piyushsain
Tera Guru
Tera Guru

Hi @Martyna ,

Use this in the condition of scheduled job:

answer = (new Date().getDay() == 5) && (new Date().getDate() <=7);
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Piyush Sain

View solution in original post

5 REPLIES 5

Peter Bodelier
Giga Sage

Hi @Martyna 

 

You can use this:

 

answer = isFirstFridayOfMonth();
function isFirstFridayOfMonth() {
  // Get the current date
  const currentDate = new Date();

  // Get the first day of the month
  const firstDayOfMonth = new Date(currentDate.getFullYear(), currentDate.getMonth(), 1);

  // Check if the current day is a Friday
  const isFriday = currentDate.getDay() === 5;

  // Check if the current day is the first Friday of the month
  const isFirstFridayOfMonth = isFriday && firstDayOfMonth.getDay() === 5;

  return isFirstFridayOfMonth;
}

 


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

Thank you Peter!

@Martyna This code will work on any Friday of the Month, not the first Friday

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Piyush Sain

piyushsain
Tera Guru
Tera Guru

Hi @Martyna ,

Use this in the condition of scheduled job:

answer = (new Date().getDay() == 5) && (new Date().getDate() <=7);
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Piyush Sain