4

我遇到了OrmLiteDateTimeOffset支持的问题。我住在英国,相信这是相关的。

我有一个表,其中有一列类型为DateTimeOffset

尝试插入DateTimeOffset列时出现以下 SQL 错误:

Msg 241, Level 16, State 1, Line 1
Conversion failed when converting date and/or time from character string.

我已经运行了SQL Profiler,可以看到正在执行的 SQL 如下:

INSERT INTO "Table"
    ("InsertedDateTime")
VALUES
    ('23/04/2013 09:30:48 +00:00')

我很确定这是dd/mm/yy vs mm/dd/yy的问题。如果我将 SQL 转换为以下内容,它可以正常工作:

INSERT INTO "Table"
    ("InsertedDateTime")
VALUES
    ('23-Apr-2013 09:30:48 +00:00')

我是否有一些配置不正确,或者我需要做些什么才能使其正常工作?

4

1 回答 1

2

您只需要更改默认日期格式。试试这个——

SET DATEFORMAT dmy

DECLARE @temp TABLE (col DATETIMEOFFSET)

INSERT INTO @temp (col)
SELECT '23-Apr-2013 09:30:48 +00:00'

INSERT INTO @temp (col)
SELECT '2013-04-23 09:30:48 +00:00'

INSERT INTO @temp (col)
SELECT '2013/04/23 09:30:48 +00:00'

INSERT INTO @temp (col)
SELECT '23/04/2013 09:30:48 +00:00'
于 2013-04-23T11:56:07.900 回答