Skip to content

Support custom timezone offsets for MySQL DateTime fields #29517

@textxin886

Description

@textxin886

Feature Summary

Allow users to specify a target timezone for DateTime fields in Prisma Schema or via the connection string for MySQL, ensuring that the stored value matches the specified timezone instead of being forced to UTC.

Use Cases & Problem Description

In MySQL, the DATETIME type does not store timezone metadata. Currently, Prisma's Rust engine forces all DateTime values to be interpreted as UTC. This causes significant issues for regional projects (like those in China, UTC+8) where database administrators and legacy SQL tools expect to see local time in the database. For example, a record created at 15:00 local time is stored as 07:00 by Prisma, making manual database inspection and third-party reporting confusing.

Proposed Solution

Provide a way to specify a storage timezone in the schema or connection string. For example:
model Post {
id Int @id
createdAt DateTime @db.DateTime @Timezone("Asia/Shanghai")
}
Or, make the ?timezone=+08:00 parameter in the MySQL connection string actually affect how the Prisma Query Engine serializes/deserializes DateTime values.

Alternative Solutions

Currently, I have to manually "shift" the time using libraries like Luxon with the 'keepLocalTime: true' flag before saving, and perform the reverse operation after fetching. This adds significant boilerplate and is prone to errors when developers forget to apply the manual conversion.

Potential Considerations

Handling Daylight Saving Time (DST) for certain regions might be complex. It may also introduce inconsistencies if different clients use different timezone settings for the same database.

Prisma Version

7.70

What part of Prisma does this affect?

Prisma Client

Additional Context

This is a very common requirement for developers in regions where local time storage is the standard practice for on-premise or regional databases.

Pre-Submission Checklist

  • I have searched existing issues to make sure this is not a duplicate
  • I have checked the Prisma roadmap to see if this is already planned
  • I have described why this belongs in Prisma Core rather than a solution in application code

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/featureA request for a new feature.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions