Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

477
Visualizações
How to pass 'YYYY-MM-DD' date format to postgresql trough prisma client?

I have a nestjs app using prisma, with following postgresql table:

Table "public.Transaction"
Column |       Type        |               
-------+-------------------+
id     | integer           |
amount | double precision  |
date   | date              |

In prisma, I defined the table as this:

model Transaction {
  id                Int      @id @default(autoincrement())
  amount            Float   
  date              DateTime @db.Date

Since I am using postgresql, I need to pass a date with 'YYYY-MM-DD' format.

I am trying to pass this format as a string:

const createdTransaction = await this.prisma.transaction.create({
  data: {
    amount: 3333,
    date: '2022-11-22',
  },
});

But I get following error:

Argument date: Got invalid value '2022-11-22' on prisma.createOneTransaction. Provided String, expected DateTime.

I know I have to pass a Date type, but using the javascript formatting, everything ends up in a string.

What value should I pass to date within nestjs?

Because if I use new Date(2022,11,22), it is accepted by prisma, but this is stored as Thu Dec 22 2022 00:00:00 GMT+0100 (Central European Standard Time), a string, which is not what postgresql expects.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I think you can just make the type of the date column string in your Transaction model.

This way you can pass the date string to PostgreSQL.

Another way is maybe to make the type number and pass the milliseconds date to PostgreSQL.

In your service before returning the object or in your frontend you can parse the date back to a string.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda