惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

AI
AI
TaoSecurity Blog
TaoSecurity Blog
H
Heimdal Security Blog
Help Net Security
Help Net Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Microsoft Azure Blog
Microsoft Azure Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Google DeepMind News
Google DeepMind News
爱范儿
爱范儿
The Cloudflare Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
人人都是产品经理
人人都是产品经理
大猫的无限游戏
大猫的无限游戏
N
News | PayPal Newsroom
V2EX - 技术
V2EX - 技术
博客园 - 【当耐特】
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
Secure Thoughts
C
CERT Recently Published Vulnerability Notes
罗磊的独立博客
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Privacy & Cybersecurity Law Blog
有赞技术团队
有赞技术团队
S
Schneier on Security
S
SegmentFault 最新的问题
Google Online Security Blog
Google Online Security Blog
H
Hacker News: Front Page
The Last Watchdog
The Last Watchdog
Schneier on Security
Schneier on Security
PCI Perspectives
PCI Perspectives
IT之家
IT之家
Project Zero
Project Zero
博客园 - 司徒正美
P
Privacy International News Feed
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Jina AI
Jina AI
Security Latest
Security Latest
Hacker News - Newest:
Hacker News - Newest: "LLM"
腾讯CDC
C
CXSECURITY Database RSS Feed - CXSecurity.com
阮一峰的网络日志
阮一峰的网络日志
C
Check Point Blog
aimingoo的专栏
aimingoo的专栏
V
Vulnerabilities – Threatpost
W
WeLiveSecurity
NISL@THU
NISL@THU
Webroot Blog
Webroot Blog
N
Netflix TechBlog - Medium
L
Lohrmann on Cybersecurity

博客园 - 梦飞天蝎

[导入]CCNA认证培训介绍 [导入]硬盘参数解读 [导入]SCSI技术 [导入]常用的硬盘接口类型IDE、SCSI、SATA [导入]SCSI卡(图解) [导入]什么是RAID控制器 [导入]微软Office InfoPath 2003概述(转贴) [导入]关于在MOSS的编辑或新建页面隐藏栏 [导入]FTP两种传输模式小结 [导入]sp_unprepare是做什么用的 [导入]left join 的 右表 加条件 某个字段 is not null 是不是无效啊 [导入]案例入厂前和离职后的旷工都清除掉,但无法清除离职前的旷工记录喔20080304 [导入]案例做出考勤月报表20080303 [导入]SqlServer如何生成动态交叉表查询 [导入]where jzno is not null还可以怎么表达呢 [导入]案例20080220 列出台籍人员全年出勤 [导入]表变量在存储过程中出现了"必须声明变量"的错误,已经声明了啊 [导入]SQL Server字符串处理函数大全 [导入]SQL数据文件恢复高级篇
[导入]sql server 的日期转换函数
梦飞天蝎 · 2008-02-20 · via 博客园 - 梦飞天蝎
<DIV id=art style="MARGIN: 15px" width="100%"><DIV><DIV twffan="done">CREATE FUNCTION fn_DateToFormatString(@date datetime, @format varchar(20))
RETURNS varchar(20) AS BEGIN DECLARE @result varchar(20) SELECT @result = replace(replace(replace(replace(replace(replace(@format,
'yyyy',
'20' + substring(CONVERT(char(8),
@date, 3), 7, 2)),
'MM',
substring(CONVERT(char(8),
@date, 3), 4, 2)), 'dd',
substring(CONVERT(char(8),
@date, 3), 1, 2)), 'hh',
substring(CONVERT(char(8),
@date, 8), 1, 2)),
'ii',
substring(CONVERT(char(8),
@date, 8), 4, 2)), 'ss',
substring(CONVERT(char(8),
@date, 8), 7, 2))
RETURN @result END
</DIV><DIV twffan="done"> </DIV><DIV twffan="done">好像只能用于 2000 版本,7。0 不行</DIV></DIV><DIV> </DIV><DIV> </DIV><DIV>
Sql Server 常用日期格式
发布于:2006-2-24 17:53:25 已被阅读:<SCRIPT src="../hits.asp?ID=1166"></SCRIPT> 158

SQL Server中文版的默认的日期字段datetime格式是yyyy-mm-dd Thh:mm:ss.mmm
例如:
select getdate()
2004-09-12 11:06:08.177
整理了一下SQL Server里面可能经常会用到的日期格式转换方法:
举例如下:
select CONVERT(varchar, getdate(), 120 )
2004-09-12 11:06:08

select replace(replace(replace(CONVERT(varchar, getdate(), 120 ),'-',''),' ',''),':','')
20040912110608

select CONVERT(varchar(12) , getdate(), 111 )
2004/09/12

select CONVERT(varchar(12) , getdate(), 112 )
20040912

select CONVERT(varchar(12) , getdate(), 102 )
2004.09.12

select CONVERT(varchar(12) , getdate(), 101 )
09/12/2004

select CONVERT(varchar(12) , getdate(), 103 )
12/09/2004

select CONVERT(varchar(12) , getdate(), 104 )
12.09.2004

select CONVERT(varchar(12) , getdate(), 105 )
12-09-2004

select CONVERT(varchar(12) , getdate(), 106 )
12 09 2004

select CONVERT(varchar(12) , getdate(), 107 )
09 12, 2004

select CONVERT(varchar(12) , getdate(), 108 )
11:06:08

select CONVERT(varchar(12) , getdate(), 109 )
09 12 2004 1

select CONVERT(varchar(12) , getdate(), 110 )
09-12-2004

select CONVERT(varchar(12) , getdate(), 113 )
12 09 2004 1

select CONVERT(varchar(12) , getdate(), 114 )
11:06:08.177

</DIV></DIV>