Output dates in MMDDYYYY format efficiently(有效地以 MMDDYYYY 格式输出日期)
问题描述
我有下面的脚本,结果 YYYYMMDD
.但是,我需要 MMDDYYYY
格式的结果.
I have the below script which results YYYYMMDD
. However, I need the result in MMDDYYYY
format.
有人可以帮忙吗?我不希望数字之间有破折号/笔划/句点.
Can someone please assist? I want no dash/stroke/periods between the numbers.
SELECT CONVERT(VARCHAR(10), RowUpdateDateTime, 112)
from MyTable
结果:20141113
我希望它看起来像 11132014
.
我尝试了 FORMAT
语法,但它需要很长时间才能运行.
I tried the FORMAT
syntax but it was taking forever to run.
推荐答案
查看 CONVERT()
文档:没有一种格式与您正在寻找的完全匹配.看起来 110
是最接近的.我们可以通过添加一个 REPLACE() 调用来完成:
Take a look at the CONVERT()
documentation: none of formats match exactly what you're looking for. It looks like 110
is the closest. We can finish by adding a REPLACE() call:
SELECT REPLACE(CONVERT(VARCHAR(10), RowUpdateDateTime, 110),'-','') from MyTable
我也想知道你为什么要这样做.大多数情况下,您的客户端代码可以更有效地处理此类转换.
I also wonder why you're doing this at all. Much of the time, a conversion like this can be handled more effectively by your client code.
这篇关于有效地以 MMDDYYYY 格式输出日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:有效地以 MMDDYYYY 格式输出日期


- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 更改自动增量起始编号? 2021-01-01
- SQL 临时表问题 2022-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01