Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2024 08:06 PM
I need to convert todays date to a workday. example 5th februvary is the 3rd workday of that month
Solved! Go to Solution.
1 ACCEPTED SOLUTION
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-03-2024 11:17 PM
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
6 REPLIES 6
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-03-2024 11:17 PM
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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2024 04:28 PM
Hello here is the code additional comments.
(function numberOfWorkdays() {
var gdt = new GlideDateTime(); // get current date time object
var oneday = 24 * 60 * 60 * 1000; // number of milliseconds in a day
var cmon = gdt.getMonthLocalTime(); // get today's month
var mon = cmon; // initialize variable to keep track of month for previous days
var wdays = 0; // initialize counter to keep track of number of workdays
while ( mon === cmon ) { // loop until the current month is different from today's month
var dofw = gdt.getDayOfWeekLocalTime(); // day of week of current date
if( dofw >= 1 && dofw <= 5) wdays++; // increment counter if it is a weekday ( Mon = 1 Sunday =7)
gdt.subtract(oneday); // go to previous day by subtracting 1 day from current date
mon = gdt.getMonthLocalTime(); // get month of current (modified) date
}
return wdays;
}())
Hope the comments help
--
Bala