Im new to prisma, I have a list of appointments and I want to get the list of today's appointments, the problem is that DateTime in prisma is a timestamp and I want to compare todays date in the format dd-mm-yy I tried this:
const allRendezVous = await prisma.Rendez_vous.findMany({
where : {
date : Date.now(),
}
});
anyone can help me with this please?
A more general solution (helpful to a wider audience) is to have a function that returns a date string in YYYY-MM-DD
format for any given Rendez-vous date or defaults to today
. The function adjusts for time-zone.
const getDate = (givenDate = new Date()): string => {
const offset = givenDate.getTimezoneOffset();
givenDate = new Date(givenDate.getTime() - offset * 60 * 1000);
return givenDate.toISOString().split('T')[0];
};
The query
const allRendezVous = await this.prisma.rendez_vous.findMany({
where: { date: { gte: new Date(getDate()) } },
orderBy: { date: 'desc' },
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.