html
<form [formGroup]="searchForm" (ngSubmit)="search()">
<div class="row">
<div class="col">
<input type="date" class="form-control" formControlName="startDate" >
</div>
<div class="col">
<input type="date" class="form-control" formControlName="endDate" >
</div>
<div class="col">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
ts.
searchForm = new FormGroup({
startDate: new FormControl(),
endDate: new FormControl(),
}
);
i need the date in this format: '2022-12-31'
but when I display it using console.log(this.searchForm.value.startDate), the output is simply:
Output : 2022-12-31
I attempted to fix this by converting startDate to a Date object like this:
startDate = new Date(this.searchForm.value.startDate)
however, the Output remained as: 1970-01-01T00:00:00