Age Calculator Tool Free Download
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Age Calculator</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: rgba(0, 0, 0, 0.5);
}
.popup {
background-color: white;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
padding: 25px;
width: 300px;
text-align: center;
}
h2 {
color: #2c3e50;
margin-top: 0;
}
input[type="date"] {
width: 100%;
padding: 10px;
margin: 10px 0;
border: 1px solid #ddd;
border-radius: 5px;
box-sizing: border-box;
}
button {
background-color: #3498db;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s;
}
button:hover {
background-color: #2980b9;
}
#result {
margin-top: 20px;
font-size: 18px;
font-weight: bold;
color: #2c3e50;
min-height: 27px;
}
</style>
</head>
<body>
<div class="popup">
<h2>Age Calculator</h2>
<p>Enter your date of birth:</p>
<input type="date" id="dob" max="">
<button onclick="calculateAge()">Calculate Age</button>
<div id="result"></div>
</div>
<script>
// Set max date to today
document.getElementById('dob').max = new Date().toISOString().split('T')[0];
function calculateAge() {
const dobInput = document.getElementById('dob').value;
const resultDiv = document.getElementById('result');
if (!dobInput) {
resultDiv.textContent = "Please enter your date of birth";
return;
}
const dob = new Date(dobInput);
const today = new Date();
let age = today.getFullYear() - dob.getFullYear();
const monthDiff = today.getMonth() - dob.getMonth();
if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < dob.getDate())) {
age--;
}
// Calculate months and days if you want more precise age
let months = today.getMonth() - dob.getMonth();
let days = today.getDate() - dob.getDate();
if (days < 0) {
months--;
// Get days in previous month
const prevMonthLastDay = new Date(
today.getFullYear(),
today.getMonth(),
0
).getDate();
days += prevMonthLastDay;
}
if (months < 0) {
months += 12;
}
resultDiv.innerHTML = `Your age is: <span style="color:#e74c3c">${age}</span> years<br>`;
resultDiv.innerHTML += `Or <span style="color:#e74c3c">${age*12 + months}</span> months<br>`;
resultDiv.innerHTML += `Or <span style="color:#e74c3c">${Math.floor((today - dob) / (1000 * 60 * 60 * 24))}</span> days`;
}
</script>
</body>
</html>
How to Use This Tool:
1. Copy the entire code above
2. Paste it into a new HTML file (e.g., `age-calculator.html`)
3. Open the file in a web browser
Features:
- Clean popup-like UI design
- Date picker for easy input
- Calculates age in years, months, and days
- Prevents future dates from being selected
- Responsive design that works on mobile and desktop