时间小时或小时和分钟SQL Server

时间:2011-11-29 05:49:03

标签: sql sql-server sql-server-2008

我需要计算生产力。

Productivity = some count/ no of Hrs

我有时间在HH:MM

例如,如果我需要时间1 hrs 30 minutes

生产力将是

Productivity = some count / 1.3?

OR

Productivity = some count / 1.5?

2 个答案:

答案 0 :(得分:3)

如果你有1小时30分钟,那就是1.5小时。您可以将计算结果设为:yourValue / 1.5以获得units / Hour

中的效率

你可能想要这样的东西:

SELECT DATEPART(HOUR, @yourTime) + (DATEPART(MINUTE, @yourTime) / 60.) AS pHours;

或更完全类似于此,其中@Time是任务花了多长时间:

SELECT @workAccomplished /
   (DATEPART(HOUR, @Time) + (DATEPART(MINUTE, @Time) / 60.)) AS Productivity;

如果你除以1.3,你将计算1小时18分钟,0.3小时= 18分钟。

答案 1 :(得分:0)

        declare @workaccomplished int = 240
        declare @timeworked int = (SELECT DATEDIFF(hour, '2007-05-07 09:53:01', '2007-05-08 09:53:01'))

        --datediff parameters: hour, startingtime , endtime
        declare @productivity numeric(8,4) = @workaccomplished / @timeworked

        select @productivity