将时间转换为00:00:00转换为int C#

时间:2017-04-23 18:58:10

标签: c# asp.net .net

我正在创建一个aspx.net页面,其中有一个总时间字段。我想在文本框中将总时间显示为INT,这样我就可以将其乘以每小时的成本,以获得总成本文本框。 Example

2 个答案:

答案 0 :(得分:1)

您可以在日期时间字段中使用.TotalHours

答案 1 :(得分:0)

我最后只是以另一种方式执行任务。我刚刚在我的SQL查询中添加了另一列。对于那些寻找解决方案的人,我的查询是

DECLARE @techID INT 
SET @techID = 1
SELECT        Customer.firstName, Customer.lastName, Invoice.invoiceDate, 
Invoice.timeStart, Invoice.timeEnd, Techs.hourlyRate, 
            CAST(DATEADD(MINUTE, DATEDIFF(MINUTE, Invoice.timeStart, 
Invoice.timeEnd), '2017-01-01 00:00:00.000') AS TIME) AS [Total time], 
            CAST(DATEDIFF(hh, timeStart, timeEnd) AS INT) * hourlyRate AS 
[Total Cost]
FROM            Customer INNER JOIN
                     Invoice ON Customer.customerID = Invoice.CustomerID 
INNER JOIN
                     Techs ON Invoice.TechID = Techs.techID
WHERE        (Techs.techID = @techID)
GROUP BY Customer.firstName, Customer.lastName, Invoice.invoiceDate, 
Invoice.timeStart, Invoice.timeEnd, Techs.hourlyRate

这提供了下表Updated Example