Coder-Meca
Coder-Meca

Reputation: 409

Moment js returns invalid date after format

I have the following code in my application :

moment(dateD, 'YYYY-MM-DD').format('DD/MM/YYYY')

The dateD is like this 2020-05-30 00:00:00.0 i want to parse it to this Format DD/MM/YYYY but the problem my code returns Invalid Date.

Upvotes: 0

Views: 2332

Answers (1)

Chromegear
Chromegear

Reputation: 36

2020-05-30 00:00:00.0 can't be parsed with the format string YYYY-MM-DD (the time is missing).

Simplest solution for your case would be:

moment(dateD.split(" ")[0], 'YYYY-MM-DD').format('DD/MM/YYYY')

Upvotes: 2

Related Questions