Update someones birthday with javascript

Posted by user2768038 on Stack Overflow See other posts from Stack Overflow or by user2768038
Published on 2013-10-20T09:39:31Z Indexed on 2013/10/20 9:54 UTC
Read the original article Hit count: 151

Filed under:

So far the only mathematical way I can think of doing it is this:

var age = 18
var today = new Date();

var myDate = new Date();
myDate.setFullYear(2013,3,13); /* My birthday is april 13th */

var y = (today - myDate);

var days = ( y / (1000*60*60*24));

if(days >= 360){
    var age = age +1;
}

if(days >= 720){
    var age = age +1;
}

//etc......
document.write(age);

Is there a better way of doing the if statements? so that I don't have to write one out for every year? I can't think!

© Stack Overflow or respective owner

Related posts about JavaScript