ITPUB论坛 » MS SQL Server » 截取时间
新一届的微软MVP评选已经开始,欢迎各位推荐!
2008-7-3 14:16 xuweihong_hw
截取时间

sqlserver 如何按照yyyymmddhh截取时间

2008-7-3 15:24 javens
convert(varchar(8),date,112)   yyyymmdd
自己去查一下幫助

2008-7-3 18:10 xuweihong_hw
大哥我要获取yyyymmddhh

2008-7-3 18:40 smthgdin
这样就行了。

select
Convert(varchar(10),getdate(),112)
+ substring(replace(Convert(varchar,getdate(),120),'-',''),10,2)

需求好奇怪的要求。

2008-7-4 12:48 jvkojvko
自己查一下convert帮助啊,很详细的,参数用121可以实现的,取相应的位数就可以了

2008-7-8 20:14 xiebinren
无语

2008-7-10 21:52 liuhongzhe
你也可以想个笨法,分别借去月、日、年。之后组合一下就行。想怎么组合都可以。

2008-7-11 12:38 cofei
[quote]原帖由 [i]smthgdin[/i] 于 2008-7-3 18:40 发表 [url=http://www.itpub.net/redirect.php?goto=findpost&pid=10845518&ptid=1016016][img]http://www.itpub.net/images/common/back.gif[/img][/url]
这样就行了。

select
Convert(varchar(10),getdate(),112)
+ substring(replace(Convert(varchar,getdate(),120),'-',''),10,2)

需求好奇怪的要求。 [/quote]

2008-7-11 22:50 zaorv
1楼的方法连接截取小时的函数

2008-7-12 12:48 马鞍
[quote]原帖由 [i]zaorv[/i] 于 2008-7-11 22:50 发表 [url=http://www.itpub.net/redirect.php?goto=findpost&pid=10923737&ptid=1016016][img]http://www.itpub.net/images/common/back.gif[/img][/url]
1楼的方法连接截取小时的函数 [/quote]

没这个必要,convert就可以解决了

2008-7-12 15:40 jvkojvko
select replace(replace(convert(varchar(13),getdate(),120),'-',''),' ','')

select replace(replace(convert(varchar(13),getdate(),126),'-',''),'T','')

2008-7-12 22:56 liuhongzhe
笨但万能的方法,因为你需要的格式比较特殊。
给你写一下吧,可能有拼写错误。
select datepart(year,getdate()),datepart(month,getdate()),datepart(day,getdate()),datepart(hour,getdate())
返回1行记录,4个字段。
foreach遍历这一行,组合成字符串,就得到你想要的结果了。

页: [1]
查看完整版本: 截取时间


Powered by ITPUB论坛