Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
639 views
in Technique[技术] by (71.8m points)

sql-server - 如何在SQL中从DateTime格式获取时间?(How to get Time from DateTime format in SQL?)

I want to get only Time from DateTime column using SQL query using SQL Server 2005 and 2008 Default output:

(我想使用SQL Server 2005和2008默认输出使用SQL查询从DateTime列获取时间:)

AttDate                   
==
2011-02-09 13:09:00    
2011-02-09 14:10:00    

I'd like this output:

(我想要这个输出:)

AttDate                Time 
==
2011-02-09 13:09:00    13:09
2011-02-09 14:10:00    14:10
  ask by Jig12 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

SQL Server 2008:

(SQL Server 2008:)

select cast(AttDate as time) [time]
from yourtable

Earlier versions:

(早期版本:)

select convert(char(5), AttDate, 108) [time]
from yourtable

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...