How to Change the date format in "mm/dd/yyy" of Date field returned by mongoose query

1,587 views
Skip to first unread message

Dipesh gupta

unread,
Sep 1, 2015, 1:30:41 PM9/1/15
to Mongoose Node.JS ODM
var query = Trips.findOne({"_id":tripId},function (err, trip) {
     
if (err)
         res
.send(err);
      console
.log(trip.startDate);
      res
.json(trip);
 
});

The above code prints the date field like "2015-08-30T10:40:35.476Z".
But i want to change this Date in "mm/dd/yyyy" format. So that i can display the date in jQuery Datepicker.


Dipesh gupta

unread,
Sep 1, 2015, 1:57:08 PM9/1/15
to Mongoose Node.JS ODM
Even After doing 

         
 delete trip.tripEndDate;
            trip
.tripEndDate="07/10/1986";          
            console
.log(trip.tripEndDate);

It prints in Date Format not in mm/dd/yyyy

Emanuele DelBono

unread,
Sep 1, 2015, 2:33:39 PM9/1/15
to mongoo...@googlegroups.com
It's not related to moongoose, it's a general javascript concern. 
You should use something like moment.js (http://momentjs.com) to print the date in the correct format.

--
Documentation - http://mongoosejs.com/
Plugins - http://plugins.mongoosejs.com/
Bug Reports - http://github.com/learnboost/mongoose
Production Examples - http://mongoosejs.tumblr.com/
StackOverflow - http://stackoverflow.com/questions/tagged/mongoose
Google Groups - https://groups.google.com/forum/?fromgroups#!forum/mongoose-orm
Twitter - https://twitter.com/mongoosejs
IRC - #mongoosejs
---
You received this message because you are subscribed to the Google Groups "Mongoose Node.JS ODM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-orm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages