Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

474
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!