Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert birthday to age in angularjs

I want to display age of all my users to grid. I am reading data from facebook.I am not storing it at anywhere.

i am displaying date like :

{{ friend.birthday }}

How can i display age instead of displaying birthday.

if it is possible to create filters than how to create filter and how to apply it.

like image 505
Hitesh Modha Avatar asked Jul 22 '14 09:07

Hitesh Modha


1 Answers

Idk why I can never reply to people, says I need more rep but to rep I need to comment.. whatever.

In response to @Dean Christian Armada's, I kept getting an error regarding the filter. But changing to the following seems to work fine so I do appreciate it!

$scope.getAge = function(birthday){
    var birthday = new Date(birthday);
    var today = new Date();
    var age = ((today - birthday) / (31557600000));
    var age = Math.floor( age );
    return age;
  }

And for the HMTL

{{ getAge(birthdate) }}
like image 113
Chris Weems Avatar answered Nov 07 '22 05:11

Chris Weems