将时间除以2

时间:2017-05-29 14:27:11

标签: c# sql

是否有一个简单的解决方案来划分时间?例如,将04:00:30除以2,得到2:00:15?

select FIRMA, NR, CAST(Zeit AS TIME(0)) as Zeit 
  from [2_2017] 
where Art='D' 
and Zeit is not Null 
and Zeit !='00:00:00'and Tour_1 ='0' 
order by Firma,NR

1 个答案:

答案 0 :(得分:1)

也许你首先需要将时间转换为某个整数,如秒,分钟,午夜时分,然后再将其转换为午夜

   DECLARE @zeint time = '23:00:15'
declare @midnight  time ='00:00:00'
select 
    dateadd(SECOND,
                (DATEDIFF(SECOND,@midnight, @zeint)/2)
            ,@midnight) as half