0

Initially i have this date format in bootstrap date picker

08-18-2023
<input bsDatepicker [bsConfig]="bsConfig" [bsValue]="maxFromDate" [minDate]="today"  (bsValueChange)="setfromdate($event)"/>

<button (click)="clear()">clear</button>

setfromdate(date) 
{
this.maxFromDate=this.datepipe.transform(new Date(date), 'MM-dd-yyyy'),
}

clear()
{
this.maxFromDate=null;
}      

          

i have used new Date also to convert it to Date

i'm trying to set the date but getting Type 'string' is not assignable to type 'Date.

user3653474
  • 3,393
  • 6
  • 49
  • 135
  • What exactly do you want to achieve? – Sven Märki Aug 16 '23 at 13:14
  • @SvenMärki after calling clear method i want to set the date again using method setfromdate function – user3653474 Aug 16 '23 at 13:15
  • It looks like `bsValue` is expecting a `Date`, but you're passing it the output of `this.datepipe.transform()` which is a `string`. – D M Aug 16 '23 at 14:58
  • Instead of trying to format the date then passing the formatted string to `bsValue`, pass the actual date to `bsValue` and let the control handle formatting. There's a related question here: https://stackoverflow.com/questions/46159487/how-to-change-the-date-format-in-the-datepicker-of-angular-ngx-bootstrap-inside – D M Aug 16 '23 at 15:00

0 Answers0