Michael Murata Michael Murata - 10 months ago 43
Javascript Question

Moment() vs predefined Moment() date

I am a bit confused on how the Moment functions work (such as

, etc).

My question is: how do I obtain the start of the week from a predefined date?

Consider these two calls on

moment().startOf('week') // Returns a moment object with date set to Sun Sep 18 2016 ...


moment(new Date("9/21/16")).startOf('week') // Returns a moment object with date set to Wed Sep 21 2016 ...

Why don't these behave in the same way? The same is true when using
instead of

Answer Source

How do you know that moment(new Date("9/21/16")).startOf('week') is returning Wed Sep 21 2016? Are you looking inside the returned object? If so, I think you're just seeing the input date. You should use moment.format() function to get the actual date:

// "September 18, 2016"

// "September 18, 2016"
moment("9/21/16", "MM/DD/YY").startOf("week").format("LL");

// "September 18, 2016" on my system (not recommended)
moment(new Date("9/21/16")).startOf("week").format("LL");