Advertisement
BumbleguppysRevenant

How Old Are You?

Mar 8th, 2012
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function howOld(dateString) {
  2.  
  3.     dateString = dateString.split('/');
  4.    
  5.     var today = new Date();
  6.     var bday = new Date(parseInt(dateString[2]), parseInt(dateString[0]), parseInt(dateString[1]));
  7.  
  8.     var milliseconds =  today.getTime() - bday.getTime();
  9.     var minutes = Math.round(milliseconds / (1000 * 60));
  10.     var hours = Math.round(milliseconds / (1000 * 60 * 60));
  11.     var days = Math.round(milliseconds / (1000 * 60 * 60 * 24));
  12.     var months = Math.round(milliseconds / (1000 * 60 * 60 * 24 * (365.25 / 12.0)));
  13.    
  14.     return 'Months: ' + months + '\nDays: ' + days + '\nHours: ' + hours + '\nMinutes: ' + minutes;
  15. }
  16.  
  17. console.log(howOld(prompt('What is your birthday?(MM/DD/YYYY)')));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement