0

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"?

1
  • pipe = new DatePipe('en-US') and then obj.created_date = this.pipe.transform(obj.created_date, 'yyyy-MM-dd hh:mm') Commented Oct 12, 2022 at 14:09

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.