title: value getDay is not a function Typescript Angular
body: <p>I found a similar question but it did not answer the issue I am facing.</p>
  
  <p>I am trying to parse a date into a string. Here is my implementation.</p>
  
  <pre><code>export class DataFormater {
  
      formatDDMMMYYY(date: Date): string {
          return date.getDay().toString() + '/' + date.getMonth().toString() + '/' + date.getFullYear().toString();
      }
  
  }
  </code></pre>
  
  <p>but I get an error saying <code>date.getDay() is not a function</code>? When I look at the doc's it is a number, hence the <code>.toString()</code>. Has anyone encountered this or found a better way to implement a way to parse a date to a string to a desired output. </p>
  
  <p>-------------- Full implementation ----------</p>
  
  <pre><code>&lt;input class="form-control" placeholder="yyyy-mm-dd"
                             name="dp" ngbDatepicker #d="ngbDatepicker" [(ngModel)]="fromDate" (keyup)="setFilter()"&gt;
  </code></pre>
  
  <p>in component</p>
  
  <pre><code>toDate: Date;
  fromDate: Date;
  
  constructor(private dateFormater: DataFormater) {
      this.toDate = new Date();
      this.fromDate = new Date();
  }
  
  setFilter() {    
          if (this.toDate != null) {
              console.log(this.toDate + " in toDate...");
              this.filter.toDate = this.dateFormater.formatDDMMMYYY(this.toDate);
          }
          if (this.fromDate != null) {
              this.filter.fromDate = this.dateFormater.formatDDMMMYYY(this.fromDate);
          }
          this.filterEmitter.emit(this.filter);
      }
  </code></pre>
  
  <p>DateFormater</p>
  
  <pre><code>export class DataFormater {
  
      constructor(){
          console.log(this.formatDDMMMYYY(new Date))
      }
  
      formatDDMMMYYY(date: Date): string {
          date = new Date(date);
          return date.getDay().toString() + '/' + date.getMonth().toString() + '/' + date.getFullYear().toString();
      }
  
  }
  </code></pre>