将区域字符串转换为 datetimeoffset
我有一个以下格式的日期字符串:
9/28/2006 5:53:03 PM
我需要将其转换为与 datetimeoffset
列兼容的格式(例如 2006-09-28 17:53:03 GMT
)。
我找不到任何转换函数来获取这种格式。寻找 Excel 或 SQL Server 转换。
I have a date string in the following format:
9/28/2006 5:53:03 PM
I need to convert this to a format compatible with a datetimeoffset
column (e.g. 2006-09-28 17:53:03 GMT
).
I couldn't find any convert function to get this format. Looking either for Excel or SQL Server conversion.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要获得您在问题中要求的显式字符串输出,您可以这样做,但是该格式与
datetimeoffset
不兼容,主要是因为GMT
在那里无效。String 输出:
由于您实际上似乎根本不需要您询问的格式,而是需要将此值插入到
datetimeoffset
列中,因此您的显式格式问题中询问的内容无关紧要。尝试(不清楚您的所有时间是否都是 UTC 且这就是您想要的,或者您是否真的打算转换为 GMT,遵守 DST IIRC):输出
那应该是与您的
datetimeoffset
列兼容。下次请解释整个问题。在任何一种情况下,请不要使用
FORMAT()
(如评论中建议的那样),尤其是在大规模情况下。FORMAT() 很好,但是……
格式< /code> 是一个方便但昂贵的函数,第 1 部分
格式< /code> 是一个方便但昂贵的函数,第 2 部分
To get the explicit string output you asked for in the question, you can do this, however that format is not compatible with
datetimeoffset
, mainly becauseGMT
is invalid there.String output:
Since you actually don't seem to want the format you asked about at all and rather need to insert this value into a
datetimeoffset
column, then the explicit format you ask about in the question is irrelevant. Try (and not clear if all your times are in UTC and that's what you want, or if you really meant to translate to GMT, which observes DST IIRC):Output
That should be compatible with your
datetimeoffset
column. Next time please explain the entire problem.In either case, please don't use
FORMAT()
for this (as suggested in a comment), especially at scale.FORMAT()
is nice and all, but…FORMAT
is a convenient but expensive function, part 1FORMAT
is a convenient but expensive function, part 2