2

This is one of the models from my schema:

model playlist {
  id              Int             @id @default(autoincrement())
  list            String          @db.VarChar(34)
  duration        DateTime?       @db.Time(0)
}

And I would like to add a time value when I am creating a new record. But it seems that I can only add value with the DateTime type.

I tried just passing a String but that doesnt work and I get and error. This is the error:

Argument duration: Got invalid value '00:01:29' on prisma.createOneplaylist. Provided String, expected DateTime or Null.

Is there a way to only add the time or am I forced to use DateTime format?

1 Answer 1

5

You would always need to send a Date object in this case. For e.g. this is how I would set the time using date-fns.

import set from 'date-fns/set'

await prisma.playlist.create({
    data: {
      list: 'list',
      duration: set(new Date(), { hours: 1, minutes: 10 }),
    },
})

A similar parsing mechanism can be used when you retrieve the time.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.