title: Calculate age from date in Angular 6 + Angular Material
body: <p>I am trying to calculate age from the date, picked up with Angular Material date picker, but have an error. Below is my code:</p>
  
  <p>HTML</p>
  
  <pre><code>&lt;div class="input-container"&gt;
      &lt;mat-form-field&gt;
        &lt;input matInput [matDatepicker]="dp" placeholder="Date of Birth" [(ngModel)]="birthdate" formControlName="firstCtrl"&gt;
        &lt;mat-datepicker-toggle matSuffix [for]="dp"&gt;&lt;/mat-datepicker-toggle&gt;
        &lt;mat-datepicker #dp&gt;&lt;/mat-datepicker&gt;
      &lt;/mat-form-field&gt;
  
      &lt;mat-form-field&gt;
        &lt;input matInput placeholder="Age" value="{{age}}" [(ngModel)]="age" formControlName="firstCtrl" required&gt;
      &lt;/mat-form-field&gt;
      &lt;button mat-button (click)="CalculateAge()"&gt;Calculate Age&lt;/button&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>TS</p>
  
  <pre><code>export class ClaimSubmitComponent implements OnInit {
    public birthdate: Date;
    public age: number;
  
    public CalculateAge(): void {
  if (this.birthdate) {
    var timeDiff = Math.abs(Date.now() - this.birthdate.getTime());
    this.age = Math.floor(timeDiff / (1000 * 3600 * 24) / 365.25);
      }
    }
  </code></pre>
  
  <p>But I get an error like: </p>
  
  <pre><code>ERROR TypeError: this.birthdate.getTime is not a function
  </code></pre>
  
  <p>What am I doing wrong? Thank you!</p>