Javascript age calculation on IPad -


on every regular browser, date calculated .. 38 year old.

on ipad not number (nan) error... why?

function getage(date) {     var today = new date();     var birthdate = new date(date);     var age = today.getfullyear() - birthdate.getfullyear();     var m = today.getmonth() - birthdate.getmonth();     if (m < 0 || (m === 0 && today.getdate() < birthdate.getdate())) {         age--;     }     return age;  } 

edit: nan @ ipad, ie8 , correct working @ firefox&chrome

you need following transformations on input date string work on ipad/iphone.

function getage(date) {     date = date.replace(/-/,"/").replace(/-/,"/"); //substitute - /     var today = new date();     var birthdate = new date(date);     var age = today.getfullyear() - birthdate.getfullyear();     var m = today.getmonth() - birthdate.getmonth();     if (m < 0 || (m === 0 && today.getdate() < birthdate.getdate())) {         age--;     }     return age; } 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -