How can we convert todays date to a workday

JPSS
Tera Contributor
I need to convert todays date to a workday. example 5th februvary is the 3rd workday of that month
1 ACCEPTED SOLUTION

Hi @JPSS   yes the function as written should convert today's date to workday (of current month)

Give it a try in Background scripts

 

--

Bala

View solution in original post

6 REPLIES 6

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @JPSS 

 

OOTB not available and to do this, need to read the calendar and then calculate. 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Can  you please help me with the script

BalaG
Kilo Sage

Hi @JPSS   here is javascript function that can do that.

 

(function numberOfWorkdays() {
var gdt = new GlideDateTime();
var oneday = 24 * 60 * 60 * 1000;

// get current month
var cmon = gdt.getMonthLocalTime();
var mon = cmon;
var wdays = 0;

while ( mon === cmon ) {

    var dofw = gdt.getDayOfWeekLocalTime();
    if( dofw >= 1 && dofw <= 5) wdays++;
    gdt.subtract(oneday);
    mon = gdt.getMonthLocalTime();
}
return wdays;
}())

 

If this answer solved your issue please mark it as a solution or mark it 👍 helpful if it was of help.

--

Bala Guthy

JPSS
Tera Contributor

Hi Bala,

 

 the date would varies. the function should convert todays date to workday