• Instructions to Ask a Question

    For any assistance, please click the "Ask a Question" button and select the Pabbly product for which you require support.

    We offer seven comprehensive applications designed to help you efficiently manage and grow your business:

    Our support team endeavors to respond within 24 business hours (Monday to Friday, 10:00 AM to 6:00 PM IST). We appreciate your understanding and patience.

  • Due to Holi celebrations, our team will have limited availability. While we’ll continue to monitor threads, responses may be slightly delayed. Normal operations will resume on Thursday, 5th March 2026.

How to find working days between any 2 dates

Status
Not open for further replies.
Use the Javascript Code below in the "Code by Pabbly" action step.

Use the Action Event by the name of "Run Javascript (Beta)".

1694236593916.png



Copy and paste the code exactly as shown below.

JavaScript:
function workdaysBetweenDates(date1Str, date2Str) {
    const date1 = new Date(date1Str);
    const date2 = new Date(date2Str);

    let workdays = 0;
 
    // Iterate through each day and count workdays
    while (date2 >= date1) {
        const dayOfWeek = date1.getUTCDay();
     
        if (dayOfWeek !== 0 && dayOfWeek !== 6) { // 0 is Sunday, 6 is Saturday
            workdays++;
        }
     
        // Move to the next day
        date1.setUTCDate(date1.getUTCDate() + 1);
    }
 
    return workdays;
}

// Sample dates
const startDate = '2023-09-01';
const endDate = '2023-09-30';

const workdaysDifference = workdaysBetweenDates(startDate, endDate);
return(`The number of workdays between ${startDate} and ${endDate} is ${workdaysDifference}.`);


Make sure to change dates in the following variables in the code. The date is the format of YYYY-MM-DD

JavaScript:
// Sample dates
const startDate = '2023-09-01';
const endDate = '2023-09-30';
 
Status
Not open for further replies.
Top