Home > Blockchain >  Angular: Type string is not assignable to type date
Angular: Type string is not assignable to type date

Time:10-13

In Angular, I wrote a code as below.

obj.created_date = formatDate(obj.created_date, 'yyyy-MM-dd hh:mm', 'en-US'); // initial value of created_date is 2022-08-12T20:17:46.00.000 01.00

FYI, the type of created_date is Date.

However, in here, I see the error as - type 'string' is not assignable to type 'date'.

If I amend new Date before the formatDate(...) then I see the unwanted result. How can I get the result with the format "yyyy-MM-dd hh:mm"?

CodePudding user response:

formatDate return a string

as obj.created_date is of type Date you can't affect a string in it

you will have to affect formatDate result in a String type variable

  • Related