Answer the question
In order to leave comments, you need to log in
Getting data incorrectly, depending on the date?
When receiving data, depending on the date, the data is displayed incorrectly. I do it this way.
Get date:
const date = new Date();
date.setDate(date.getDate());
const tasks = await TaskModel.find({
userId: `${req.user.id}`,
time: { $eq: dates },
}).exec();
const date = new Date();
date.setDate(date.getDate() - 1);
const tasks = await TaskModel.find({
userId: `${req.user.id}`,
time: { $gte: dates },
}).exec();
Answer the question
In order to leave comments, you need to log in
date.setDate(date.getDate());
this line makes no sense (does nothing).
If you want to cut off the time of the date (and in fact put 0 hours 0 minutes, etc.), then this is explicitly divided: .
If the date is needed in the standard time zone, then use , after which instead of - .
Well, on your server, dates should be stored without time, otherwise no , but only + . date.setHours(0, 0, 0, 0)
eq
gte
lte
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question