Search code examples
typescriptpostgresqlnestjsprisma

Prisma DateTime Format Issue


I was practicing around with Nest Js and prisma and i wanted to store DateTime in database according to my timezone. `

joining      DateTime     @db.Timestamptz(5)

` Adding the @db.Timestamptz fixed my issue for storing the timezone specific time. But when I get it back from the db it automatically changes into GMT in the format 2022-12-01T06:56:54.240Z

Any ideas on why is this happening?

I'm new to Nest and Prisma. So i don't have any idea on what's up with this.


Solution

  • Prisma Client returns all DateTime as native Date objects. The time would be stored in the UTC format in the database. See this section of the docs. Storing DateTime in UTC is standard practice, so you shouldn’t face any issues. This is especially useful when the frontend needs to show times in different timezones; for these cases, the database should use one standard time format.