我想从DateTime列使用SQL查询只得到时间 使用SQL Server 2005和2008 默认的输出:
AttDate
==
2011-02-09 13:09:00
2011-02-09 14:10:00
我想要这样的输出:
AttDate Time
==
2011-02-09 13:09:00 13:09
2011-02-09 14:10:00 14:10
我想从DateTime列使用SQL查询只得到时间 使用SQL Server 2005和2008 默认的输出:
AttDate
==
2011-02-09 13:09:00
2011-02-09 14:10:00
我想要这样的输出:
AttDate Time
==
2011-02-09 13:09:00 13:09
2011-02-09 14:10:00 14:10
当前回答
从datetime获取时间而不使用毫秒堆栈的最简单方法是:
SELECT convert(time(0),getDate())
其他回答
试试这个,它会起作用的:
CONVERT(VARCHAR(8),DATETIME,114)
供您参考。
select convert(char(5), tbl_CustomerBooking.CheckInTime, 108) AS [time]
from tbl_CustomerBooking
select cast (as time(0))
这是一个很好的条款。例如:
(select cast(start_date as time(0))) AS 'START TIME'
SQL Server 2008:
SELECT cast(AttDate as time) [time]
FROM yourtable
早期版本:
SELECT convert(char(5), AttDate, 108) [time]
FROM yourtable
select AttDate,convert(char(5), AttDate, 108)[时间]从你的表名