在sql中将时间仅转换为hh:mm
我目前正在处理下面的查询,但是我希望我的结果以hh:mm格式显示。我正在使用convertchar,mycolumnName,108,但是我的结果仍然显示为hh:mm:ss。我只需要hh:mm。有没有办法在hh:mm中得到这个结果?请提前告知谢谢在sql中将时间仅转换为hh:mm,sql,sql-server-2008,Sql,Sql Server 2008,我目前正在处理下面的查询,但是我希望我的结果以hh:mm格式显示。我正在使用convertchar,mycolumnName,108,但是我的结果仍然显示为hh:mm:ss。我只需要hh:mm。有没有办法在hh:mm中得到这个结果?请提前告知谢谢 select distinct clientid, timein , timeout, calculation, convert(char, calculation, 108) as CalculationResult f
select distinct
clientid, timein , timeout, calculation,
convert(char, calculation, 108) as CalculationResult
from
calculationTable
where
timein is not null and timeout is not null
输出:
Clientid timein timeout calculation CalculationResult
------------------------------------------------------------------------
0012345 09:00:00 05:00:00 1900-01-01 08:00:00 08:00:00
试试这个
select
distinct clientid,
timein,
timeout,
calculation,
convert(varchar(5), calculation, 108) as CalculationResult
使用字符5,
SELECT DISTINCT clientid,
timein,
timeout,
calculation,
convert(VARCHAR(5), calculation, 108) AS CalculationResult
FROM calculationTable
WHERE timein IS NOT NULL
AND timeout IS NOT NULL