按工作小时数计算工资

Ste*_*hRT 2 vb6 math datetime

嘿所有,我想弄清楚如何计算员工退休时的工资.这是我目前使用的代码:

 Dim theStartTime As Date
 Dim theEndTime As Date
 Dim totalTime As String

 theStartTime = "16:11:06"
 theEndTime = "18:22:01"
 totalTime = Format(CDbl((theEndTime - theStartTime) * 24), "#0.0")
Run Code Online (Sandbox Code Playgroud)

所以可行的工作时间是:2小时11分钟

现在,根据我上面的计算代码,我得到2.2.我需要添加什么才能让它计算2:11而不是2:20的正确时间?

大卫

dlr*_*as2 7

请注意,2.2小时不是 2:20,而是2:12.

更改

Format(CDbl((theEndTime - theStartTime) * 24), "#0.0")
Run Code Online (Sandbox Code Playgroud)

Format(theEndTime - theStartTime, "h:mm")
Run Code Online (Sandbox Code Playgroud)

您正在获得正确的价值,只需在打印时将其四舍五入.theEndTime - theStartTime是一个时间跨度等于两次之间的差异.正如您所发现的那样,将它乘以24将为您提供不同的小时数.但是,您必须再次除以24才能使用日期/时间格式.

查看VB6中格式化日期和时间的所有方法.