Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

483
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda