typeorm icon indicating copy to clipboard operation
typeorm copied to clipboard

@UpdateDateColumn() does not store UTC date in MSSQL even with useUtc: true in NestJS

Open ankurmehta102 opened this issue 3 months ago • 2 comments

Issue description

When using @UpdateDateColumn() in TypeORM within a NestJS application, and useUtc: true is set in the TypeORM module configuration, the column does not store dates in UTC.

Expected Behavior

Both insert and update operations should record UTC time, not the server’s local time.

Actual Behavior

Despite useUtc: true, the @UpdateDateColumn() stores local server time in MSSQL. This happens on both insert and update, so the timestamps are not UTC at all.

Steps to reproduce

  1. Configure TypeORM module with useUtc: true
TypeOrmModule.forRootAsync({
      imports: [ConfigModule],
      useFactory: (configService: ConfigService) => {
        return {
          type: 'mssql',
          host: configService.get('database').host,
          port: configService.get('database').port,
          username: configService.get('database').username,
          password: configService.get('database').password,
          database: configService.get('database').database,
          entities: [User, Link],
          synchronize:
            configService.get('node_env') === Environment.Development,
          extra: {
            trustServerCertificate:
              configService.get('node_env') === Environment.Development,
          },
          options: {
            useUTC: true,
          },
        };
      },
      inject: [ConfigService],
    }),
  1. Define an entity with @UpdateDateColumn()
@Entity()
export class ExampleEntity {
  @PrimaryGeneratedColumn()
  id: number;

  @UpdateDateColumn({ type: 'datetime2' })
  updatedAt: Date;
}

My Environment

Dependency Version
Operating System Window 11
Node.js version 22.19.0
Typescript version 5.1.3
TypeORM version 11.0.0
mssql driver version 11.0.1

Additional Context

No response

Relevant Database Driver(s)

  • [ ] aurora-mysql
  • [ ] aurora-postgres
  • [ ] better-sqlite3
  • [ ] cockroachdb
  • [ ] cordova
  • [ ] expo
  • [ ] mongodb
  • [ ] mysql
  • [ ] nativescript
  • [ ] oracle
  • [ ] postgres
  • [ ] react-native
  • [ ] sap
  • [ ] spanner
  • [ ] sqlite
  • [ ] sqlite-abstract
  • [ ] sqljs
  • [x] sqlserver

Are you willing to resolve this issue by submitting a Pull Request?

No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.

ankurmehta102 avatar Sep 25 '25 05:09 ankurmehta102

See also https://github.com/typeorm/typeorm/issues/11498

tolgap avatar Oct 02 '25 17:10 tolgap

@alumni Can you assign this issue to me?

Cprakhar avatar Dec 05 '25 17:12 Cprakhar