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

Categories

0 votes
694 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 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...