Assign a saved datetime value in database to Datepicker value

366 Views Asked by At

I have a kendo-datepicker in my page to insert date to table and this works fine

<kendo-datepicker [value]="paymentDate" [(ngModel)]="paymentDate"></kendo-datepicker>

I use the same web page to show the details of the saved record

this.paymentDate = response.paymentDate;

but when I assign the same value in the database to kendo-datepicker during the page load, I gives me the following error

The 'value' should be a valid JavaScript Date instance.

I tried to format the string but not successful.

1

There are 1 best solutions below

0
On

Initialize paymentDate with JavaScript's Date object.

paymentDate = new Date();
// or,
paymentDate = new Date('December 17, 1995 03:24:00');


Checkout MDN to know furthur about Date object.


Note: I'm not sure the two way binding will work at this case or not. But the official documentation says that have valueChange event that you can listen.

Example:

In Template:

<kendo-datepicker
    (valueChange)="onChange($event)"
    [value]="paymentDate"
    >
</kendo-datepicker>

in Component:

 paymentDate = new Date();

 public onChange(value: Date): void {
    this.paymentDate= value;
  }