Article Image
read

JS Hack - Calculating Age

In this post I will share an extremely useful hack to apply in JavaScript. If you ever need to create a function that calculates age based on a date of birth, I recommend that you use this function that makes an extremely performative spell:


function howOld(dateString) {
  var bday = +new Date(dateString);
  return ~~((Date.now() - bday) / (31557600000));
}

howOld('06/11/1990'); //26

Blog Logo

Robson Fagundes


Published

Image

Robson Fagundes

Software Engineer, entrepreneur, founder of Rdicom and AI Software Engineer focused on HealthTech, PACS, DICOM, cloud platforms, APIs, integrations, automation, databases and software architecture.

Back to Overview