This question already has an answer here:
i want to get the trunc date with such format :
20190326
this code in my schema :
dateCreated: {
type: Date,
default: Date.now
}
2019-03-26T01:05:43.778Z
This question already has an answer here:
i want to get the trunc date with such format :
20190326
this code in my schema :
dateCreated: {
type: Date,
default: Date.now
}
2019-03-26T01:05:43.778Z
db.collection.aggregate([{
$project: {
date: {
$dateToString: {
format: "%d%m%Y",
date: "$dateCreated"
}
}
}
}])
You can set formate according to requirement. Sample data here.
this solved it :
const date = new Date();
const today = date.getUTCFullYear().toString()+ (date.getUTCMonth()+1)+date.getUTCDate().toString();
export const taskSchema = new Schema ({
dateCreated: {
type: String,
default: today
}
});
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!