2 Day Business Calculator

// Function to calculate business days between two dates
function countBusinessDays(startDate, endDate) {
let businessDays = 0;
let currentDate = new Date(startDate);

// Loop through each date between start and end date
while (currentDate <= endDate) { // Check if the current day is a business day (Monday to Friday) if (currentDate.getDay() !== 0 && currentDate.getDay() !== 6) { businessDays++; } // Move to the next day currentDate.setDate(currentDate.getDate() + 1); } return businessDays; } // Function to check if the entered date is 2 business days from today function checkTwoBusinessDays() { // Get the current date const today = new Date(); // Get the date entered by the user (assuming the date field is named 'date_field') const enteredDate = new Date(document.querySelector('input117260941').value); // Ensure the entered date is valid if (isNaN(enteredDate)) { alert('Please enter a valid date.'); return; } // Calculate the number of business days between today and the entered date const businessDays = countBusinessDays(today, enteredDate); // Check if there are exactly 2 business days between today and the entered date if (businessDays === 2) { alert('There are exactly 2 business days between today and the entered date.'); } else { alert('There are not exactly 2 business days between today and the entered date.'); } } // Trigger the check when the user changes the date (you can also trigger on form submission or other events) document.querySelector('input117260942').addEventListener('change', checkTwoBusinessDays);