<div style="background:#fff; max-width:450px; margin:20px auto; padding:25px; border-radius:12px; box-shadow:0 5px 20px rgba(0,0,0,0.1); border:1px solid #eee; font-family:sans-serif;">
<h3 style="text-align:center; color:#222; margin-top:0; font-size:24px;">वय कॅल्क्युलेटर (Age Calculator)</h3>
<hr style="border:0; border-top:1px solid #eee; margin-bottom:20px;">
<div style="margin-bottom:15px;">
<label style="display:block; margin-bottom:6px; font-weight:bold; color:#444;">तुमची जन्मतारीख निवडा:</label>
<input type="date" id="user_dob" style="width:100%; padding:12px; border:1px solid #ccc; border-radius:6px; font-size:16px; box-sizing:border-box;">
</div>
<div style="margin-bottom:20px;">
<label style="display:block; margin-bottom:6px; font-weight:bold; color:#444;">या तारखेपर्यंत वय मोजा:</label>
<input type="date" id="target_date" style="width:100%; padding:12px; border:1px solid #ccc; border-radius:6px; font-size:16px; box-sizing:border-box;">
</div>
<button onclick="getCalculatedAge()" style="width:100%; background:#2575fc; color:#fff; padding:14px; border:none; border-radius:6px; font-size:18px; font-weight:bold; cursor:pointer; transition:0.2s;">वय मोजा</button>
<div id="final-result-box" style="display:none; margin-top:20px; padding:15px; background:#f9f9f9; border-left:5px solid #2575fc; border-radius:4px;">
<p style="margin:0 0 5px 0; font-weight:bold; color:#333;">तुमचे अचूक वय:</p>
<div id="display-age" style="font-size:18px; color:#222; font-weight:bold;"></div>
</div>
</div>
<script>
document.getElementById('target_date').valueAsDate = new Date();
function getCalculatedAge() {
var birthInput = document.getElementById('user_dob').value;
var currentInput = document.getElementById('target_date').value;
if (!birthInput) {
alert('कृपया जन्मतारीख निवडा!');
return;
}
var bDate = new Date(birthInput);
var cDate = new Date(currentInput);
if (bDate > cDate) {
alert('जन्मतारीख आजच्या तारखेपेक्षा जास्त असू शकत नाही!');
return;
}
var years = cDate.getFullYear() - bDate.getFullYear();
var months = cDate.getMonth() - bDate.getMonth();
var days = cDate.getDate() - bDate.getDate();
if (days < 0) {
months--;
var prevMonth = new Date(cDate.getFullYear(), cDate.getMonth(), 0);
days += prevMonth.getDate();
}
if (months < 0) {
years--;
months += 12;
}
document.getElementById('display-age').innerHTML = years + " वर्षे, " + months + " महिने आणि " + days + " दिवस.";
document.getElementById('f
inal-result-box').style.display = 'block';
}
</script>
0 Comments