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
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
}
});