qz
const form = document.getElementById('duration-calculator'); const result = document.getElementById('result');
form.addEventListener('submit', (event) => { event.preventDefault();
const startDate = new Date(document.getElementById('start-date').value); const endDate = new Date(document.getElementById('end-date').value);
let years = endDate.getFullYear() - startDate.getFullYear(); let months = endDate.getMonth() - startDate.getMonth(); let days = endDate.getDate() - startDate.getDate();
if (days < 0) {
const monthDays = new Date(endDate.getFullYear(), endDate.getMonth(), 0).getDate();
days += monthDays;
months--;
}
if (months < 0) {
months += 12;
years--;
}
result.textContent = `Duration: ${years} years, ${months} months, ${days} days`;
});