The CreatorCon Call for Content is officially open! Get started here.

To check if today (current date) is the first Saturday of the month.

Chandler2
Tera Guru

I have a scheduled job set to run daily but I need to check in condition script that if today is first Saturday of the current month? Then only run the scheduled job.

Can someone please share the code needs to be used for that in the condition area?

Thanks!

7 REPLIES 7

@Chandler 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Chandler2 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Chandler,

May 7th is the first Saturday on this month. I've changed to script to "dayOfMonth <= 7" from "dayOfMonth < 7" to include 7th.

var today = '2022-05-07 00:00:10';
var gdt = new GlideDateTime();
gdt.setDisplayValue(today);

var dayOfWeek = gdt.getDayOfWeekLocalTime();
var dayOfMonth = gdt.getDayOfMonthLocalTime();

if(dayOfWeek == 6 && dayOfMonth <= 7 ){
	gs.info(gdt.getDisplayValue() + " is first Saturday");
} else {
  gs.info(gdt.getDisplayValue() + ' is not first Saturday');
}

Execution result:

Test by changing 'today' value.

case 1: today = '2022-05-07 00:00:00'

*** Script: 2022-05-07 00:00:10 is first Saturday

case 2: today = '2022-06-03 00:00:00

*** Script: 2022-06-03 00:00:00 is not first Saturday