0

I am working on an Angular project and when I'm sending the Date to the data.service. I have debugged that the date returned is correct {year:2020, month:11, day:02} but after moment(date).format("YYYY-MM-DD") a month is added to the date making it Invalid (13th month doesn't exist ).

moment(this.date).format("YYYY-MM-DD");

{year: 2020, month: 12, day: 4}
Invalid date

{year: 2020, month: 11, day: 4}
2020-12-04
  • [It returns `"2020-12-02"`](https://jsbin.com/guruhorimu/edit?js,console) which [is correct](https://momentjs.com/docs/#/parsing/object/). There is no 13th month. How exactly are you calling Moment and what do you get? – VLAZ Nov 02 '20 at 06:34
  • If you can please post the code you have applied! – Punit Gajjar Nov 02 '20 at 06:34
  • If you look at the momentjs [docs](https://momentjs.com/docs/#/parsing/string-format/) the Month format is `1-12` – Ricardo Sanchez Nov 02 '20 at 06:47
  • Months are zero indexed *when programatically specifying them*. Using the formatting option they are indexed starting from one. This is normal when you want to *display* a date, you want it in a normal human-readable fashion. When you enter a date, you do it via the backwards and legacy way systems have done it for the past 40 or more years which has more or less become the norm. – VLAZ Nov 02 '20 at 06:50

0 Answers0