Skip to content

add datetime2 data type. #1596

@ping-maxwell

Description

@ping-maxwell

issue

MSSQL datetime only stores time to an accuracy of ~3.33 milliseconds. This means when you insert a JS date into a datetime column, SQL Server rounds the fractional seconds to the nearest 0, 3, or 7 ms increment.

Example:
JS: 2025-09-26T01:00:00.001Z
MSSQL stored: 2025-09-26T01:00:00.003Z

solution

In order to resolve this, we must create the datetime field as datetime2 - however as of now using db.schema.alterTable(...).addField("name", "datetime2", ...) won't work.

For more context, here's a post on stackoverflow talking about this specific issue regarding mssql:
https://stackoverflow.com/questions/7823966/milliseconds-in-my-datetime-changes-when-stored-in-sql-server

Additional info:
I require the .addField specifically as this is being built into a wrapper function used in the better-auth repo.

Metadata

Metadata

Assignees

No one assigned

    Labels

    apiRelated to library's APIenhancementNew feature or requestgood first issueGood for newcomersmssqlRelated to MS SQL Server (MSSQL)typescriptRelated to Typescript

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions