• 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.

    🚀 Exclusive Lifetime Offers 🚀

    We invite you to take advantage of our special one-time payment plans, providing lifetime access to select applications:

    • 🔥 Pabbly Connect — Lifetime Access for $249View Offer
    • 🔥 Pabbly Subscription Billing — Lifetime Access for $249View Offer
    • 🔥 Pabbly Chatflow — Lifetime Access for $249View Offer

    Make a one-time investment and enjoy the advantages of robust business management tools for years to come.

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