XXcode
XXcode

Reputation: 29

Angular :The specified value "2022-03-30T00:00:00.000+00:00" does not conform to the required format, "yyyy-MM-dd"

I'm trying to put a date from my database to my input type="date" field. Strings works perfectly, they all go to form when except date.

My input type is date on the form.

my form :

  <input  [value]="candidat.birthDate" type="date">

candidat:

export class Candidat {
     birthDate!:Date;
}

Upvotes: 1

Views: 1390

Answers (2)

Nahom Ersom
Nahom Ersom

Reputation: 88

why don't use pipe, just like below:

<input  value={{candidat.birthDate | date}} type="date">

Upvotes: 0

The Fabio
The Fabio

Reputation: 6260

This is more of a general HTML input error

When you use type="date" in you input element, you have to comply to its expected values. The specification illustrates that:

value includes the year, month, and day, but not the time. The time and datetime-local input types support time and date+time input

So to make it work you need to adjust datTime string 2022-03-30T00:00:00.000+00:00 you are using. Using the first 10 chars should do the trick:

<input  [value]="candidat.birthDate?.substr(0,10)" type="date">

Upvotes: 1

Related Questions