Hi, I have a startTime field with DateTime @db.tim...
# orm-help
r
Hi, I have a startTime field with DateTime @db.time , what is the format to insert the time ? I tried "090000" but my seed break
r
@Rain 👋 You need to pass a Date object with the time set to
09:00
.
r
I actually tried this
new Date(0,0,0,9,0)
but the seed still stuck with Error. As work around I changed the type to string for now. this is the sample code where it fail to create
Copy code
await prisma.workingHour.create({
        data: {
          businessId: business.id,
          opens: {
            create: new Array(5).fill(1).map((v, idx) => {
              return { day: idx + 1, startTime: new Date(0,0,0,9,0), endTime: new Date(0,0,0,18,0) };
            }),
          },
        },
      });
r
Works fine, tested on Postgres 13:
Copy code
model User {
  id   Int      @id @default(autoincrement())
  time DateTime @db.Time(0)
}
And the query:
Copy code
let date = new Date()
  date.setHours(9)
  date.setMinutes(0)
  date.setSeconds(0)
  await prisma.user.create({
    data: {
      time: date,
    },
  })
This is the output: