#Timezone default

1 messages · Page 1 of 1 (latest)

rustic ruin
#

How to set default timezone on Prisma ORM to save DateTime on MySQL with default value current_timestamp?
My TZ is "America/Sao_Paulo" (UTC-3).

hexed plover
#

Hello 👋

Prisma will use the timezone that is configured in your MySQL Database. You can configure it in your database by running this SQL:

SET GLOBAL time_zone = '-3:00';
SET SESSION time_zone = '-3:00';
rustic ruin
#

Hello Nurul!

Okay, I'll test. Thank you for your attention

#

i am setting the configuration in the database but this error keeps appearing.

#

the row 1 is manually insert with current date and time. Row 2 is inserted by prisma

#

The code of insert's with prisma.

#

Prisma models

rustic ruin
#

@hexed plover can you help-me?

merry cargo
#

@rustic ruin

Based on my research, here's 2 options:

  1. Do as Nurul suggested and set the global timezone:
    https://dev.mysql.com/doc/refman/8.0/en/time-zone-support.html
SET GLOBAL time_zone = 'Your_Desired_Timezone';
SET SESSION time_zone = 'Your_Desired_Timezone';
  1. Convert the timestamp at creation/update:
    https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_convert-tz
model Sectors {
  createdAt DateTime @default(dbgenerated("CONVERT_TZ(NOW(),'Current_Default_Timezone','Your_Desired_Timezone')"))
}
rustic ruin
#

Hello @merry cargo !

Not work 😦

#

It was the prism version. I found that version 5.0.0 is not working this.

I went back to 4.17.0-dev.61 and it worked correctly

merry cargo
#

Oh dang! Wasn't aware of that current issue as I'm using postgres. Thanks for letting me know amd nice job, on figuring it out

hexed plover
#

Hey @rustic ruin
That's strange. Can you check of you get the same error in prisma 4.16.0?