Use PDIs? Take our 5-minute survey to help shape the PDI roadmap.

How to exclude weekends while calculating date in custom form in flow ?

VIKASM535239375
Kilo Sage

How to exclude weekends while calculating date in custom form in flow ?

After Lookup records on Custom Form and For each condition

For eg 1.DueDate + 5 days Logic as below 

 

Duedate relative before 4 days ago and Due date relative after 6days ago

 

Similarly 

1.DueDate + 3 days Logic as below 

 

Duedate relative before 2 days ago and Due date relative after 4 days ago

 

Provide Weekend exclusion logic based on above condition in Flow in ServiceNow.

 

After which Notification to be triggered.

1 REPLY 1

Ankur Bawiskar
Tera Patron

@VIKASM535239375 

are you trying to get difference between 2 dates or 2 date/time in flow?

if yes then use flow variable and use "Set Flow Variables" flow logic and refer below scripts and get that

var startDateGdt = new GlideDateTime();
startDateGdt.setValue('startDateHere');

var endDateGdt = new GlideDateTime(current.end_date_here);

var days = getDateDiffExcWeekends(startDateGdt,endDateGdt);

function getDateDiffExcWeekends(start,end){
        var days = 0;
        while (start < end) {
            start.addDaysUTC(1);
            if (start.getDayOfWeekUTC() != 6 && start.getDayOfWeekUTC() != 7){
                days++ ;
            }
        }
        return days+1;
}

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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