How to select items in prisma with date GTE > current date

Viewed 7567

Hi there I'm new and prisma and trying to select future dates in prisma and not grab any 'expired' days.

I'm seeing in the docs that there is a prisma.now() but cant see it in the console when I log out cosole.log(prisma)

Does anybody know a good solution to this?

My created_at is grabbing this format: 2022-01-13 12:00

app.get("/ques", async function (req, res) {
  console.log("PRISMA", prisma.NOW());
  const allQues = await prisma.que.findMany({
    where: {
      created_at: {
        gte: prisma.NOW(),
      },
    },
  });
  res.status(200).send(allQues);
});
1 Answers

I'm not sure that such thing even exist? (prisma.NOW())

now() is just the function that you can use in your schema file to set default value, for example:

model User {
  registeredAt     DateTime @default(now())
}

In your app code you can just use regular javascript Date object, for example:

  const allQues = await prisma.que.findMany({
    where: {
      created_at: {
        // new Date() creates date with current time and day and etc.
        gte: new Date()
      },
    },
  });
Related