Need to calculate age from date of birth

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #1730

    Hello, basically what the title says.

    I would like to have a code that I can input in the about me page to show my age in realtime.

    For example, I’m John and I am [code here] years old.

    Google search did not really help as most codes are not very user friendly and need separate plugins. I just want to run it inside of a block.




    function _calculateAge(birthday) { // birthday is a date
    var ageDifMs = – birthday.getTime();
    var ageDate = new Date(ageDifMs); // miliseconds from epoch
    return Math.abs(ageDate.getUTCFullYear() – 1970);

    const dateOfBirth = new Date(’11/15/1995′);
    console.log(_calculateAge(dateOfBirth) + ” years old”);
    just put whatever your date of birth is in the date of birth variable, and then instead of console log just use it to change whatever text you want


    This made me think of this….

    While not as picky as the clip, things like the location of the viewer (and if you are calculating server side, where the server is located) can be a little tricky that 24 hour period around midnight of their birthday.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.