Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...