• Instructions to Ask a Question

    Click on the "Ask a Question" button and select the application for which you would like to ask questions.

    We have 5 different products namely - Pabbly Connect, Pabbly Subscription Billing, Pabbly Email Marketing, Pabbly Form Builder, Pabbly Email Verification.

    The turnaround time is 24 hrs (Business Hours - 10.00 AM to 6.00 PM IST, Except Saturday and Sunday). So your kind patience will be highly appreciated!

    🚀🚀Exclusive Discount Offer

    Just in case you're looking for any ongoing offers on Pabbly, you can check the one-time offers listed below. You just need to pay once and use the application forever -
     

    🔥 Pabbly Connect One Time Plan for $249 (🏆Lifetime Access) -  View offer 

    🔥 Pabbly Subscription Billing One Time Plan for $249 (🏆Lifetime Access) - View offer

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