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 which can be directly assign it in an HTML5 “date” input element.And this has to be rendered using jade and Handlebars.
Similar to something like var brthday = Person.DOB.tosome_suitable_form); and then <input type="date" value="brthday"> or
(instead of html syntax jade and Handlebars syntax is required). How do I 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.