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?