I have a MongoDB schema like this
var Person = new Schema({
"Name": { type: String, required: true },
"DOB": { type: Date, "default": Date.now }
});
And a new object is created( NodeJs using mongoose ODM)
{
"Name": "Dany",
"id": "50ae0cb32c46b2901c000001",
"_v": 0,
"DOB": "2012-11-22T12:54:43.852Z"
}
I can retrieve this object and DOB from it.What I want is:- To convert this DOB into some suitable format and directly assign it in an HTML5 "date" element .And this has to be rendered using jade .Similar to something like var brthday = Person.DOB.tosome_suitable_form);
and then <input type="date" value="brthday ">
(instead of html syntax jade syntax is required) .How to do this?
Try moment.js, it is an almost standard date module for nodejs. You can use moment(doc.DOB).format('whatever_format_you_want')
. You can see the formats from their docs.