- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2025 03:49 AM
Hi,
User can Select 5 days from today excluding weekend (Saturday, Sunday).
I have written a UI policy, which is working for - "Start date should be 5 days from today in future"
The above script is working correctly but it's including (counting) weekend also (Saturday, Sunday).
Need help to exclude weekend and count 5 days (weekdays).
Thanks,
Nipan
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2025 05:48 AM
Hi @Nipan ,
We can achieve this using UI Policy Script or a Client Script that automatically updates a field with the calculated number of weekdays excluding weekends i.e saturday and sunday
- Using UI Policy Script
write the script as below :
function onCondition() {
var startDate = g_form.getValue('u_start_date');
var endDate = g_form.getValue('u_end_date');
// convert start and end date to objets
var start=new Date(startDate);
var end = new Date(endDate);
var weekdaysCount = 0;
// Ensure the end date is not before the start date
if (start > end) {
return;
}
for (var currentDate = new Date(start); currentDate <= end; currentDate.setDate(currentDate.getDate() + 1)) {
var dayOfWeek = currentDate.getDay(); // Get the day of the week (0 = Sunday, 6 = Saturday)
// Check if it's a weekday (Monday to Friday)
if (dayOfWeek >= 1 && dayOfWeek <= 5) {
weekdaysCount++;
}
}
g_form.setValue('u_weekdays', weekdaysCount);
}
The above script calculates the weekdays , excluding weekends.
- Using Client Script.
- create a new onchange client script as below
- The above Script calculates the weekdays and excludes the weekends
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2025 05:48 AM
Hi @Nipan ,
We can achieve this using UI Policy Script or a Client Script that automatically updates a field with the calculated number of weekdays excluding weekends i.e saturday and sunday
- Using UI Policy Script
write the script as below :
function onCondition() {
var startDate = g_form.getValue('u_start_date');
var endDate = g_form.getValue('u_end_date');
// convert start and end date to objets
var start=new Date(startDate);
var end = new Date(endDate);
var weekdaysCount = 0;
// Ensure the end date is not before the start date
if (start > end) {
return;
}
for (var currentDate = new Date(start); currentDate <= end; currentDate.setDate(currentDate.getDate() + 1)) {
var dayOfWeek = currentDate.getDay(); // Get the day of the week (0 = Sunday, 6 = Saturday)
// Check if it's a weekday (Monday to Friday)
if (dayOfWeek >= 1 && dayOfWeek <= 5) {
weekdaysCount++;
}
}
g_form.setValue('u_weekdays', weekdaysCount);
}
The above script calculates the weekdays , excluding weekends.
- Using Client Script.
- create a new onchange client script as below
- The above Script calculates the weekdays and excludes the weekends