Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

I'm trying to change the format of the dates I'm getting from my Mongo database. Currently, they look like this:

Fri Sep 16 2011 19:05:17 GMT+0900 (JST)

I've tried calling .toString('yyyy-MM-dd') on them but nothing changes. I don't know if they're Date objects or just raw strings.

I've tried checking the Mongoose manual and googling a bunch, but not found anything yet.

Any ideas?

2 Answers

0 votes
by (106k points)

To format dates from Mongoose in Node.js you have to create a Date object first see the code mentioned below:-

var date = new Date(dateStr);

var d = date.getDate(); 

var m = date.getMonth()+1; 

0 votes
by (108k points)

What you are doing is that you are trying to implement the following syntax:

var date = new Date();

date.toString();

The above code in MongoDB will definitely convert your date to string but that doesn’t mean that it can get rid of the UTC/GMT (standard time) date syntax. To get rid of UTC/GMT you can implement the following code:

var date = new Date();

date.toDateString();

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
2 answers
asked Oct 16, 2019 in Web Technology by Sammy (47.6k points)
0 votes
2 answers

Browse Categories

...