1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

How do I calculate age from birth date in Angular 2 using TypeScript

Discussão em 'Angular' iniciado por AshwaniKumar Singh, Junho 2, 2025.

  1. I have 2 textboxes. One textbox will accept birth date from the user and based on birth date I want to calculate and display their age in another textbox.

    Here's my component class

    Student.component.html

    <div class="row">
    <div class="input-field col m2">
    <input type="date" id="txtdate">
    </div>
    <div class="input-field col m4">
    <input type="number" id="age">
    </div>



    student.component.ts

    import { Component, OnInit } from '@angular/core';

    @Component( {
    selector: 'stud',
    templateUrl: './student.component.html'
    })
    export class StudentComponent implements OnInit
    {

    constructor() { }

    ngOnInit() { }

    }
    function CalculateAge()
    {
    var birthdate = <HTMLElement>document.getElementById( "txtdate" );
    var dt = new Date();
    var today = dt.getDate();

    }


    How do I calculate age from birth date?

    Continue reading...

Compartilhe esta Página