I'm new to Node.js and Mongodb so bear with me here.
I have read from multiple places that the best way to store dates is with new Date(). So before I store my dates in the Mongodb I convert them with new Date('10/07/2014') and turning it into 'Tue Oct 07 2014 00:00:00 GMT-0400 (Eastern Daylight Time)'.
The problem is that if I try to run a sort on the collection it sorts them by the day of the week(Mon, Tues, Wed, etc) and not by their actual dates. What am I doing wrong here? Heres some actual code:
//get date from a field and convert it
var date = new Date($('#inputDate').val());
//after storing it in the database I call this line and it sorts it by day of the week.
db.collection('gameslist').find().sort({datecompleted:1})
Printing out the sorted collection their dates come out in this order, which is by day of the week and not by actual date.
Fri Feb 20 2015 00:00:00 GMT-0500 (Eastern Standard Time) Mon Oct 13 2014 00:00:00 GMT-0400 (Eastern Daylight Time) Sun Feb 15 2015 00:00:00 GMT-0500 (Eastern Standard Time) Tue Oct 07 2014 00:00:00 GMT-0400 (Eastern Daylight Time)
I've noticed in other posts when people do something like new Date() their dates don't come out like mine but instead come out with less fluff.
Aucun commentaire:
Enregistrer un commentaire