0

How to I update the date.now in mongoose schema to show only the date in this format "MMMM Do YYYY" the mongoose schema

date: {
    type: Date,
    default: Date.now,
},

the format i get in the database

date: 2021-09-21T13:02:49.856+00:00

how to i remove the T13:02:49.856+00:00 and change the format to "MMMM Do YYYY"

1 Answers1

-1

You could extract the date first, using date.slice(0,10) on your date: 2021-09-21T13:02:49.856+00:00.Then you may want to convert it using a handy time-dealing library, like Luxon.

bobby76
  • 14
  • 2
  • A consequence of this approach is that it may change the date. Far better to parse the entire string then format the date from there. This question has been asked [many, many times before](https://stackoverflow.com/search?q=%5Bjavascript%5D+how+to+format+a+date). – RobG Sep 22 '21 at 22:32