You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Improve Timezone Support for Existing MySQL Databases configured with a Non-UTC Timezone #5051
The OS and MySQL time both are set to KST(Korea Standard Time) which is UTC+9:00.
But when create or update records with new Date(), DATETIME string doesn't respect the database's timezone and always filled with UTC time.
For example, when the current time is 2020-06-20 13:00:00 in Korea, I expect the data should be stored like below
id
created_at
1
2020-06-20 13:00:00
However, what I get is UTC time which differs -9 hours.
id
created_at
1
2020-06-20 04:00:00
How to reproduce
Set the system and MySQL timezone to Asia/Seoul or UTC+9:00
(Internal note: I can reproduce this but I think this is a usage error which is unfortunately blocked by a bug prisma/prisma-client-js#741. So I am labeling as bug/1-repro-available for now)
@pantharshit00 Yes, currently I'm inserting data with manually adjusted time (+9:00). The problem of doing this is that I always have to subtract 9 hours again from a result of Prisma.
...
createdAt: '2020-09-03T00:38:06+09:00'
~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
Argument createdAt: Got invalid value '2020-09-03T00:38:06+09:00' on prisma.createOneTip. Provided String, expected DateTime.
And unfortunately the error I issued is still happening. Prisma create or update with new Date() does not respect the system or Database timezone and always store the time string as UTC.
Here's the thing. Suppose the time in Korea is 2020-09-03 13:00.
MySQL timezone is set to Korean standard time(KST, +09:00). NOW() and CURRENT_TIMESTAMP both correctly display 2020-09-03 13:00 which means optional time fileds are automatically filled with KST time string in DB. But when I get the data with Prisma, it treats the time string as UTC and store the Date object inside the result. This mismatched time makes me always subtract 9 hours from the result.
My system timezone is also set to KST as well. date command shows Thu Sep 3 13:00:00 KST 2020 correctly.
Reacted by Moritz Hedtke, Jeong Seong Dae, Patrick Strassmann, Donghyuk Kang, Du, R.F., Fujita Hitoshi and clockwork53
And when I create a row with MySQL's CURRENT_TIMESTAMP,
The datetime field which is set to CURRENT_TIMESTAMP is not correctly resolved to MySQL's CURRENT_TIME. The times created by Prisma is UTC, which is -9 hours from KST.
It's not fixed, and it should be reopened.
Reacted by tiger, Donghyuk Kang, GeonHun Kim, JamesZhang, Alfredo, dainyzyg, nakajima, Dave Welsh, Dave Welsh, RsttRstk and 11 more
Reacted by Donghyuk Kang, GeonHun Kim, lemonQ and Gustavo Favaro
I broke down!!! Due to timezone issues, Prisma's business cannot be used in many regions. Perhaps its idea is good, but it is too idealistic, so it can only be abandoned.
@Rexpull please don't polute this thread with IA generated content which is partly wrong.
The issue is on Mysql, not Postgre
The issue comes from date conversion (SQL<=>Javascript). This is the role of the database driver which should apply timezone offset based on database timezone or a timezone driver setting. This is a standard feature, all database drivers do it properly except prisma legacy one. It should be fixed there.
Every middleware based solutions are missing a part of the thing (for example if a field is tagged as @default(now()) or @createdat, the date may be set automatically by prisma to a wrong value without being corrected by middlewares).
Then the solution is that prisma fix the mysql prisma driver or provide a way to use widely used existing drivers (mysql2, mariadb) without wierd side effects.
The last solution may already be possible with adapters but I don't know about it (I dropped prisma 3 years ago because of this issue)
#use mariadb adapter, it provides timezone config#使用 mariadb 适配器,它提供了时区配置
npm install @prisma/adapter-mariadb
make sure to set MySQL session time_zone: +00:00, which match PRISMA's behavior "We do automatic ISO conversions for JS Dates"确保设置 MySQL 会话 time_zone: +00:00,这与 PRISMA 的行为 "我们为 JS 日期自动进行 ISO 转换" 相匹配
This is indeed a temporary solution because prisma-client by default converts the new Date() into the format of the zero-timezone. This ensures correct handling of timestamps that are not in UTC.
Activity
pantharshit00 commentedon Jun 23, 2020
We do automatic ISO conversions for JS Dates so you it will contains a UTC offset by default. If you want to provide a manual offset, you will need to provide a manual string by using something like https://date-fns.org/v2.8.1/docs/formatISO
A manually offsetted date will look like this:
2020-05-05T16:28:33.983+09:00But I found a bug in our validator which I was triaging this so please follow: prisma/prisma-client-js#741
pantharshit00 commentedon Jun 23, 2020
(Internal note: I can reproduce this but I think this is a usage error which is unfortunately blocked by a bug prisma/prisma-client-js#741. So I am labeling as
bug/1-repro-availablefor now)jhaemin commentedon Jun 23, 2020
@pantharshit00 Yes, currently I'm inserting data with manually adjusted time (+9:00). The problem of doing this is that I always have to subtract 9 hours again from a result of Prisma.
pantharshit00 commentedon Jun 23, 2020
Try after prisma/prisma-client-js#741 is fixed. You can use a simple library like date-fns to get a correct offset.
https://date-fns.org/v2.8.1/docs/formatISO
So
divyenduz commentedon Jul 27, 2020
janpio commentedon Sep 2, 2020
jhaemin commentedon Sep 2, 2020
Okay, prisma/prisma-client-js#741 is not fixed yet so I cannot use the method @pantharshit00 suggested. Using the value of
formatISO(new Date())throws an error.And unfortunately the error I issued is still happening. Prisma create or update with
new Date()does not respect the system or Database timezone and always store the time string as UTC.Here's the thing. Suppose the time in Korea is
2020-09-03 13:00.MySQL timezone is set to Korean standard time(KST, +09:00).
NOW()andCURRENT_TIMESTAMPboth correctly display2020-09-03 13:00which means optional time fileds are automatically filled with KST time string in DB. But when I get the data with Prisma, it treats the time string as UTC and store the Date object inside the result. This mismatched time makes me always subtract 9 hours from the result.My system timezone is also set to KST as well.
datecommand showsThu Sep 3 13:00:00 KST 2020correctly.deps: upgrade prisma to test the issue
pantharshit00 commentedon Sep 2, 2020
Thanks @jhaemin for the update. I have candidated the other issue again so will discuss it soon for the next patch.
timsuchanek commentedon Jan 5, 2021
Thanks a lot for reporting 🙏
This issue is fixed in the latest dev version of
@prisma/cli.You can try it out with
npm i -g @prisma/cli@dev.In case it’s not fixed for you - please let us know and we’ll reopen this issue!
jhaemin commentedon Jan 5, 2021
@timsuchanek
Right now, I've tested with
@prisma/cli@devand@prisma/client@dev.Tested time is
10:55 PM (KST).Here is the tested Prisma schema model.
And I ran the codes below
and
And here is the result in mysql.
And when I create a row with MySQL's
CURRENT_TIMESTAMP,The datetime field which is set to
CURRENT_TIMESTAMPis not correctly resolved to MySQL'sCURRENT_TIME. The times created by Prisma is UTC, which is -9 hours from KST.It's not fixed, and it should be reopened.
Jolg42 commentedon Jan 6, 2021
Reopening to reproduce the latest comment @pantharshit00
160 remaining items
anaibol commentedon Oct 20, 2024
+1
kiwavi commentedon Oct 25, 2024
Update. Tested this on drizzle. It works!
chinaBerg commentedon Dec 4, 2024
I broke down!!! Due to timezone issues, Prisma's business cannot be used in many regions. Perhaps its idea is good, but it is too idealistic, so it can only be abandoned.
samimozcan commentedon Jan 8, 2025
is there any update ?
yyzclyang commentedon Apr 1, 2025
It's April 1, 2025 now, and it still hasn't addressed this issue. Maybe I should consider Drizzle
partap commentedon Jul 23, 2025
I've got the same issue, but my database is SQL Server, which Drizzle doesn't support yet :(
Back to handwritten SQL for me, I guess...
MAY-ZHONGYE commentedon Aug 25, 2025
It's August 25, 2025 now, and it still hasn't addressed this issue.
AnantaPodder commentedon Sep 3, 2025
Would love to migrate to drizzle. bye prisma.
cod378 commentedon Sep 18, 2025
Hi, the same problem with dates to MS SQL.
elechen commentedon Oct 11, 2025
#use mariadb adapter, it provides timezone config
npm install @prisma/adapter-mariadbmake sure to set MySQL session time_zone: +00:00, which match PRISMA's behavior "We do automatic ISO conversions for JS Dates"
felicienfrancois commentedon Oct 17, 2025
@Rexpull please don't polute this thread with IA generated content which is partly wrong.
Every middleware based solutions are missing a part of the thing (for example if a field is tagged as @default(now()) or @createdat, the date may be set automatically by prisma to a wrong value without being corrected by middlewares).
Then the solution is that prisma fix the mysql prisma driver or provide a way to use widely used existing drivers (mysql2, mariadb) without wierd side effects.
The last solution may already be possible with adapters but I don't know about it (I dropped prisma 3 years ago because of this issue)
oldTimer98 commentedon Nov 25, 2025
请问什么时候可以解决一下这个问题,已经五年了
JYbill commentedon Jan 16, 2026
This is indeed a temporary solution because prisma-client by default converts the new Date() into the format of the zero-timezone. This ensures correct handling of timestamps that are not in UTC.