Age Calculator Script for free

What is Age Calculation?

Hi all friends... There are many types of measurement. That means the fabric is measured in meters. Petrol, diesel, etc. are measured in liters. Vegetables, fruits, and flowers are measured in kilograms. We measure distance in km. So you can calculate your age with an age calculator. So you can calculate your exact age by using the age calculator given below using your date of birth and current date. People who want to know your exact age. Find out your age by entering your date of birth and current date in the age calculator given below.

Age is not a simple thing, there are many things like at what age should a child be enrolled in school, at what age should one go to work, and at what age should one get married. So it is very important to know your exact age. So we hope this post will be useful for you to know your exact age. Thank you and hello.

How to build this Age Calculator?

Step 1: First create the New Blog Page

Step 2: Copy the Below Age Calculator Scripts and Paste your Blog Page

<div id="main_container">
  <div id="birth_date_input">
    Birth Date: <input id="birth_date" type="date" />
  </div>
  <br />
  <div class="bubbly-button" id="calculate" style="text-align: center;">
    <span style="color: white;">Calculate Your Age</span>
  </div>
  <br />

  <div
    style="background-image: linear-gradient(120deg, #84fab0 0%, #8fd3f4 100%);"
    id="age_container"
  >
    <span id="exact_age">&nbsp;</span>
  </div>
</div>
<p>
  <i
    >* The year here is 365/366 days and the month here is 28/29/30/31 days,
    that means your birthday may not mean you will be 0 days old.</i
  >
</p>
<p><i>**Don't worry I will not share your input.</i></p>
<style>
      #main_container {
      width: 100%;
      margin: 0px;
      margin-left: auto;
      margin-right: auto;
      padding: 30px;
      border-radius: 20px;
  }

  #birth_date_input, #age_container {
      text-align: center;
      margin: 20px;
      margin-left: auto;
      margin-right: auto;
  }

  #age_container {box-shadow: rgba(17, 12, 46, 0.15) 0px 48px 100px 0px;
      margin: 40px 5px;
      padding: 20px;
      border-radius: 5px;
      font-weight: bolder;
      background: white;
      font-size: 20px;
      line-height: 40px;
  }

    #birth_date{
    border-radius: 2px;
    border-color: #3b5997;
    }

    .bubbly-button{
      background-color: #204ecf;
      border-radius: 5px;
      font-size: 15px;
      padding: 10px 0px 10px 0px;
      margin-left: 5%;
      width: 90%;
    }
    .post-title {
  text-align:center;
  }
</style>
<script src="https://code.jquery.com/jquery-latest.min.js"></script>
<script>
       $(document).ready(function(){
      $("#calculate").click(function(){
          var mdate = $("#birth_date").val().toString();
          var yearThen = parseInt(mdate.substring(0,4), 10);
          var monthThen = parseInt(mdate.substring(5,7), 10);
          var dayThen = parseInt(mdate.substring(8,10), 10);

          var today = new Date();
          var birthday = new Date(yearThen, monthThen-1, dayThen);

          var differenceInMilisecond = today.valueOf() - birthday.valueOf();

          var year_age = Math.floor(differenceInMilisecond / 31536000000);
          var day_age = Math.floor((differenceInMilisecond % 31536000000) / 86400000);

          if ((today.getMonth() == birthday.getMonth()) && (today.getDate() == birthday.getDate())) {
              alert("Happy B'day!!!");
          }

          var month_age = Math.floor(day_age/30);

          day_age = day_age % 30;

          if (isNaN(year_age) || isNaN(month_age) || isNaN(day_age)) {
              $("#exact_age").text("Invalid birthday - Please try again!");
          }
          else {
              $("#exact_age").html(getAge(new Date($("#birth_date").val()), new Date()));
          }
      });


    function getAge(date_1, date_2)
  {

  //convert to UTC
  var date2_UTC = new Date(Date.UTC(date_2.getUTCFullYear(), date_2.getUTCMonth(), date_2.getUTCDate()));
  var date1_UTC = new Date(Date.UTC(date_1.getUTCFullYear(), date_1.getUTCMonth(), date_1.getUTCDate()));


  var yAppendix, mAppendix, dAppendix;


  //--------------------------------------------------------------
  var days = date2_UTC.getDate() - date1_UTC.getDate();
  if (days < 0)
  {

      date2_UTC.setMonth(date2_UTC.getMonth() - 1);
      days += DaysInMonth(date2_UTC);
  }
  //--------------------------------------------------------------
  var months = date2_UTC.getMonth() - date1_UTC.getMonth();
  if (months < 0)
  {
      date2_UTC.setFullYear(date2_UTC.getFullYear() - 1);
      months += 12;
  }
  //--------------------------------------------------------------
  var years = date2_UTC.getFullYear() - date1_UTC.getFullYear();




  if (years > 1) yAppendix = " years";
  else yAppendix = " year";
  if (months > 1) mAppendix = " months";
  else mAppendix = " month";
  if (days > 1) dAppendix = " days";
  else dAppendix = " day";

  return "Your Age is<br/><span id=\"age\">"+years + yAppendix + ", " + months + mAppendix + ", and " + days + dAppendix +" </span>";
  }

  /*
  Wrong age calculation issue fixed / update javascript code
  By Shakil Ansary
  https://www.blogbrackets.com
  */

  function DaysInMonth(date2_UTC)
  {
  var monthStart = new Date(date2_UTC.getFullYear(), date2_UTC.getMonth(), 1);
  var monthEnd = new Date(date2_UTC.getFullYear(), date2_UTC.getMonth() + 1, 1);
  var monthLength = (monthEnd - monthStart) / (1000 * 60 * 60 * 24);
  return monthLength;
  }

  });
</script>
Birth Date:

Calculate Your Age

 

* The year here is 365/366 days and the month here is 28/29/30/31 days, that means your birthday may not mean you will be 0 days old.

**Don't worry I will not share your input.

Step 3: Publish your Page

Step 4: That's All...

Final Words

If you are the like this age calculator script Please Follow my blog on Google News

Post a Comment