nico-c
10/20/2016 - 5:59 PM

Calculate age -- also see http://codepen.io/panicbus/pen/ZpmZrb

Calculate age -- also see http://codepen.io/panicbus/pen/ZpmZrb

var today = new Date();
var pastDate = new Date("10-28-70");

function calcDate(date1, date2) {
  var diff = Math.floor(date1.getTime() - date2.getTime());
  var day = 1000 * 60 * 60 * 24;

  var days = Math.floor(diff / day);
  var minutes = Math.floor(days * 24 * 60);
  var hours = Math.floor(days * 24);
  var months = Math.floor(days / 31);
  var years = Math.floor(days / 365);
    
  var message;
  message = "If you were born on: "
  message += date2.toDateString()
  message += " you are: " + minutes + " minutes old, "
  message += hours + " hours old, "
  message += days + " days old, "
  message += months + " months old and "
  message += years + " years old."
  return message
}

answer = calcDate(today, pastDate);
console.log(answer)