TSQL日期时间ISO 8601 [英] TSQL DATETIME ISO 8601

查看:69
本文介绍了TSQL日期时间ISO 8601的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了一个要求使用 ISO 8601 日期格式的规范,是否有人知道转换代码或获取这两个示例的方式:

I have been given a specification that requires the ISO 8601 date format, does any one know the conversion codes or a way of getting these 2 examples:

ISO 8601 Extended Date 2000-01-14T13:42Z 
ISO 8601 Basic Date 20090123T105321Z


推荐答案

在SQL Server中处理日期时,ISO-8601格式可能是最好的选择,因为无论您使用哪种语言和文化设置,它都可以正常工作。

When dealing with dates in SQL Server, the ISO-8601 format is probably the best way to go, since it just works regardless of your language and culture settings.

为了将数据插入到SQL Server表中,您根本不需要任何转换代码或任何东西-只需将您的日期指定为文字字符串即可

In order to INSERT data into a SQL Server table, you don't need any conversion codes or anything at all - just specify your dates as literal strings

INSERT INTO MyTable(DateColumn) VALUES('20090430 12:34:56.790')

,您就完成了。

如果需要将日期列转换为ISO-8601格式在SELECT上,可以使用转换代码126或127(带有时区信息)来实现ISO格式。

If you need to convert a date column to ISO-8601 format on SELECT, you can use conversion code 126 or 127 (with timezone information) to achieve the ISO format.

SELECT CONVERT(VARCHAR(33), DateColumn, 126) FROM MyTable

应该给您:

2009-04-30T12:34:56.790

这篇关于TSQL日期时间ISO 8601的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆