0

How to remove the Date 00:00:00.000000 in this 2022-08-07 00:00:00.0000000 format?

<mat-form-field class="full-width1" appearance="fill">
                        <mat-label>Date</mat-label>
                        <input matInput type="date" formControlName="Date">
                    </mat-form-field>



this.Form = this.fb.group({
      deliveryDate: [this.formatDate(new Date()), Validators.required],
})


formatDate(date:Date){
    return formatDate(date, this.dateFormat, this.language)
  }
Yan
  • 149
  • 1
  • 9

2 Answers2

1

You can use angular's datepipe here.

On your app.module.ts, add datepipe like below:

import { DatePipe } from '@angular/common'
...
providers: [DatePipe]

Then, on your typescript file, do like below:

formatDate(date:Date){
   let formattedDate=this.datepipe.transform(this.date, 'yyyy-MM-dd');
   return formattedDate;
  }
Abdus Salam Azad
  • 5,087
  • 46
  • 35
0
 formatDate(date:Date){
    var year = date.getFullYear();
    var month = (date.getMonth() + 1).toString().padStart(2, "0");
    var day = date.getDate().toString().padStart(2, "0");
    var newDate = year+"-" + month.toLocaleString() + "-" + day;    
    return newDate
  }