How do I control the format in which MS-SQL Server returns datetime values?(如何控制 MS-SQL Server 返回日期时间值的格式?)
问题描述
具体来说,我希望以纯 (ISO) 格式获取日期格式:
Specifically, I wish to get the date format in a pure (ISO) format:
YYYY-MM-DD HH:mm:ss
YYYY-MM-DD HH:mm:ss
我正在寻找 SET 命令或我可以使用的东西.
I'm looking for a SET command or something that I can use.
我不想依赖服务器的文化设置.
I do not wish to rely on the culture setting of the server.
注意:我对返回日期而不是输入日期的字符串格式感兴趣.
Note: I'm interested in the string format in which dates are returned, not entered.
推荐答案
要更改默认格式,您需要添加一种新语言 (sp_addlanguage),设置它的日期格式,然后为其设置默认语言.可以在这篇旧的技术网文章上找到更多详细信息.
To change the default format you need to add a new language (sp_addlanguage), set it's date format, then set the default language to it. More details can be found on this old technet article.
如果您不想这样做,那么您可以使用 设置日期格式.
If you don't want to do that, then you can change it "per connection" using SET DATEFORMAT.
如果你不想这样做,那么你可以使用 CONVERT 将其转换为每个查询中的相关格式字符串.
And if you don't want to do that, then you can use CONVERT to convert it to the relevent format string in each query.
这篇关于如何控制 MS-SQL Server 返回日期时间值的格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何控制 MS-SQL Server 返回日期时间值的格式?
基础教程推荐
- 无法解决整理冲突 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
