如何在yii2框架中使用mssql datetimeoffset列类型

huangapple go评论71阅读模式
英文:

How to use mssql datetimeoffset column type in yii2 framework

问题

我正在编写一个需要存储带有日期、时间和时区信息的应用程序,它需要使用MSSQL。

yii2框架的MSSQL列架构仅定义了datetime列类型,没有datetimeoffset。

在这种情况下,有哪些可能的方法?

如果我想扩展Yii2 ORM以支持新的列类型,并将datetimeoffset列映射到\DateTime类,我应该如何以"yii2方式"来处理这个问题?

编辑:

看起来问题主要是在迁移中,因为

$this->createTable('{{%table_with_datetimeoffset}}', [
    'dtm' => $this->dateTime()->null()
]);

会导致列的类型为datetime2,而我需要的是datetimeoffset

英文:

I am writing an application that needs to store dates with time and timezone and it needs to use mssql.

The yii2 framework column schema for mssql defines only datetime column type, and no datetimeoffset.

What are possible approaches to this situation?

If I was to extend Yii2 orm to support a new column type and map datetimeoffset columns to \DateTime classes, how should I approach this "the yii2 way"?

EDIT:

It seems that the problem is rather in migrations only, as

$this->createTable('{{%table_with_datetimeoffset}}', [
        'dtm' => $this->dateTime()->null()
]);

results in a column of type datetime2, and I need datetimeoffset.

答案1

得分: 1

我无法写评论,所以我在这里写。
我在这里找到了'datetimeoffset' => self::TYPE_DATETIME,,这是你要找的吗?
你也可以在他们的论坛上发布帖子。

英文:

I can not write a comment, so I write here.
I found this and I see 'datetimeoffset' => self::TYPE_DATETIME, at $typeMap public property , is this what you are looking for?
You can post at their forum also.

huangapple
  • 本文由 发表于 2023年2月24日 17:36:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/75554867.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定