Abhi
Abhi

Reputation: 1574

momentjs returns wrong day name

This returns Wednesday, but it's Thursday

console.log(moment("7-03-2019").format("dddd")); //Wednesday

7-03-2019 is Thursday but moment("7-03-2019").format("dddd")

console.log(moment().format("dddd")); //Thursday

What am I doing wrong?

Fiddle: https://jsfiddle.net/da0t4pnx/

Upvotes: 1

Views: 491

Answers (2)

Yannick Y
Yannick Y

Reputation: 2846

July 3, 2019 (07-03-2019) is a Wednesday (because the dates are in the format MM-DD-YYYY) If you want March 7, 2019 (03-07-2019) you should do

console.log(moment("03-07-2019").format("dddd")); //Thursday

Upvotes: 0

dRoyson
dRoyson

Reputation: 1507

Moment.js is parsing the given input in "MM-DD-YYYY" format.

It would benefit if you mentioned the format with the input. Refer: https://momentjs.com/docs/#/parsing/string-format/

Example:

console.log(moment("7-03-2019", "DD-MM-YYYY").format("dddd"));

Upvotes: 1

Related Questions