P
Prismaβ€’11mo ago
sommeeeR

Get the next date with prisma

const course = await db.course.findFirst({
where: {
slug: params.slug,
},
include: {
courseDate: { // i want the next one from NOW
orderBy: {
from: 'asc',
}
},
},
});
const course = await db.course.findFirst({
where: {
slug: params.slug,
},
include: {
courseDate: { // i want the next one from NOW
orderBy: {
from: 'asc',
}
},
},
});
guys i want to get next courseDate from today and only that one. how can i do that using this query? πŸ™‚
6 Replies
tyler4949
tyler4949β€’11mo ago
Probably makes sense to add that to your query, right? Something like this:
where: {
slug: params.slug,
courseDate: {
gt: new Date().toUTCString()
}
},
where: {
slug: params.slug,
courseDate: {
gt: new Date().toUTCString()
}
},
sommeeeR
sommeeeROPβ€’11mo ago
ok. any particular reason to use .toUTCString()?
tyler4949
tyler4949β€’11mo ago
That was just assuming you stored your dates in UTC in the db
sommeeeR
sommeeeROPβ€’11mo ago
i do, but isnt new Date() enough? under the hood its just a timestamp since epoch
tyler4949
tyler4949β€’11mo ago
Then you’re probably good. I was just trying to convey it should be UTC time (or the same timezone as your db) My suggestion was high level, not exact code for your solution
sommeeeR
sommeeeROPβ€’11mo ago
alright:) thanks!

Did you find this page helpful?