Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

Omender Singh
Tera Guru

Hello ServiceNow Ninjas,

 

Date functions can be tricky, and many times I came across to find if today is a weekend or weekday?

There can be many ways, but I am showing one which uses ServiceNow classes & functions. 

 

You can watch the video which has line by line explanation - Click Here

 

Also please find the script below for your reference - 

-------------------------------------------------------------------------------------

var gcdt = new GlideDateTime("2022-04-24 12:02:00"); // fetch date
gs.print(gcdt);
var day =gcdt.getDayOfWeekLocalTime(); // return the local day number

if(day == 7 || day == 6)
gs.print("weekend");
else
gs.print("weekday");

------------------------------------------------------------------------------------

 

We are committed to providing easy and fast solutions.

 

Our training Videos - Click Here

Mark helpful, If this post saved your time.

Comments
Ihor Kochetkov
Tera Contributor

If you are in scope - use getDayOfWeekUTC instead of getDayOfWeekLocalTime

Version history
Last update:
‎04-25-2022 01:06 AM
Updated by: