PRISMA query for date in Node js

Viewed 29

So I'm having trouble in query with Prisma. In my db, data stored in this format in Postgres:

 [
    {
    "name":"xyz",
    "last_time_to_active":"2022-09-12 21:49:44.712811+05" // Timestamptz datatype in DB
    },
    {
    "name":"abc",
    "last_time_to_active":"2022-09-13 16:49:44.712811+05" // Timestamptz datatype in DB
    },
    {
    "name":"bcd",
    "last_time_to_active":"2022-09-11 17:49:44.712811+05" // Timestamptz datatype in DB
    }
    ]

This is my query:

await prisma.user.findMany({
      where: {
        //Now I want to find data on the basis of date only which "2022-09-10", etc.
      },
    });
1 Answers

You can compare this column to Date objects. If you want to get all timestamps on a certain day (here: 2022-09-10), that should do the trick:

prisma.user.findMany({
  where: {
    lastTimeToActive: { 
      gte: new Date("2022-09-10"), 
      lt: new Date("2020-09-11") 
    },
  },
});
Related