Exact Age Calculator with Source Code Javascript Project

With this simple tool, calculate your exact age. This Javascript project contains source code for the tool. Provide your date of birth and it will calculate your exact age.

Guide

Select your date of birth and then click on calculate age button. It will calculate age, exact age, age in terms of millisecond, age in terms of second, age in terms of Hour, age in terms of days.

Your Date of Birth
Exact Age

Source Code

You are absolutely free and 100% allowed to use the following source code for any purpose.

By using following code or above tool, you are agreeing to our privacy policy, terms conditions. (Both are present at the bottom section of this page.)

Just copy entirely following code and paste inside blogspot post, wordpress post and save or update the post. Thats it. Refresh the page. The exact age calculator app will work fine. You can even past inside widget of blog spot or wordpress.

<div id="exact-age-calculator-form">

<table class="age-calculation-form">
<tr><th><b>Your Date of Birth</b></th><td><input type="date" name="dob" id="udob"></td></tr>
<tr><th>Exact Age</th><td><div id="age-result"></div></td></tr>
<tr><td colspan="2"><button id="calculate-age">Calculate</button></td></tr>
</table>

<style type="text/css">
input[type="date"]{
outline: none;
border:none;
}
td,th{
padding:5px;
}
</style>

<script type="text/javascript">
document.getElementById("calculate-age").addEventListener('click',function(){
document.getElementById('age-result').innerHTML="";
var dob=document.getElementById('udob').value;
cdate=new Date();
var ndob=new Date(dob);
ryear=ndob.getFullYear();
age=cdate.getFullYear()-ryear;
var dit=cdate-ndob;
var ndays=parseInt(dit/(1000 * 3600 * 24));
var tdate=cdate.getFullYear()+"-"+(ndob.getMonth()+1)+"-"+ndob.getDate();
var tempdate=new Date(Date.parse(tdate))
var tempdit=cdate.getTime()-tempdate.getTime();
var restdays=parseInt(tempdit/(1000 * 3600 * 24));
if(restdays<0){
restdays=365+restdays;
}
if(ndob<cdate){
var resultContent='<p>Age: <span class="result-set">'+age+'</span></p>';
resultContent+='<p>Exact Age: <span style="color:red;">'+age+'</span> years, <span style="color:red;">'+restdays+'</span> days</p>';
resultContent+='<p>Age Till Date: <span style="color:red;">'+dit+'</span>MilliSeconds</p>';
resultContent+='<p>Age Till Date: <span style="color:red;">'+parseInt(dit/1000)+'</span> Seconds</p>';
resultContent+='<p>Age Till Date: <span style="color:red;">'+parseInt(dit/(1000*3600))+'</span> Hours</p>';
resultContent+='<p>Age Till Date: <span style="color:red;">'+parseInt(dit/(1000*3600*24))+'</span> Days</p>';
document.getElementById('age-result').innerHTML=resultContent;
}else{
ResetAgeCalData();
}
});
ResetAgeCalData();
function ResetAgeCalData(){
var resultContent='<p>Age: 0</p>';
resultContent+='<p>Exact Age: <span class="result-set">0 years, 0 days</span></p>';
resultContent+='<p>Age Till Date: 0 MilliSeconds</p>';
resultContent+='<p>Age Till Date: 0 Seconds</p>';
resultContent+='<p>Age Till Date: 0 Hours</p>';
resultContent+='<p>Age Till Date: 0 Days</p>';
document.getElementById('age-result').innerHTML=resultContent;
}
</script>
<p>Exact Age Calculator Tool Source code is available at <a href="https://onlinetools.gyanol.com/exact-age-calculator/" target="_blank" rel="noopener">OnlineTools.Gyanol.Com/Exact-Age-Calculator</a> with live example.</p>
</div>