如何按小时计算使用两个 DTPicker 的持续时间
How to compute the duration of time using two DTPicker by hour
如何使用 4 DTPicker 计算时间和超时的持续时间
Dim d1, d2, d3 As Date
Dim d4 As Integer
Dim x As Long
选项显式
Private Sub Command1_Click()
d1 = DTPicker1.Value + TimePicker.Value
d2 = DTPicker2.Value + TimePicker2.Value
x = DateDiff("h", d1, d2)
MsgBox x
End Sub
Private Sub Form_Load()
TimePicker.Format = dtpTime
TimePicker2.Format = dtpTime
结束子
============================================= =============================see attached image here
我预计 7:00 上午 - 3:00 下午 = 8 小时的输出,当我添加更多天数时,实际输出是 2 天 32 小时,应该是 16 小时
只要开始和结束时间在同一天,这应该可行:
Dim hoursPerDay As Integer
Dim days As Integer
Private Sub Command1_Click()
hoursPerDay = DateDiff("h", TimePicker1.Value, TimePicker2.Value)
days = DateDiff("d", DTPicker1.Value, DTPicker2.Value)
MsgBox hoursPerDay * days
End Sub
否则,检查hoursPerDay
是否为负数:
If hoursPerDay < 0 Then hoursPerDay = hoursPerDay + 24
如何使用 4 DTPicker 计算时间和超时的持续时间
Dim d1, d2, d3 As Date
Dim d4 As Integer
Dim x As Long
选项显式
Private Sub Command1_Click()
d1 = DTPicker1.Value + TimePicker.Value
d2 = DTPicker2.Value + TimePicker2.Value
x = DateDiff("h", d1, d2)
MsgBox x
End Sub
Private Sub Form_Load()
TimePicker.Format = dtpTime
TimePicker2.Format = dtpTime
结束子
============================================= =============================see attached image here
我预计 7:00 上午 - 3:00 下午 = 8 小时的输出,当我添加更多天数时,实际输出是 2 天 32 小时,应该是 16 小时
只要开始和结束时间在同一天,这应该可行:
Dim hoursPerDay As Integer
Dim days As Integer
Private Sub Command1_Click()
hoursPerDay = DateDiff("h", TimePicker1.Value, TimePicker2.Value)
days = DateDiff("d", DTPicker1.Value, DTPicker2.Value)
MsgBox hoursPerDay * days
End Sub
否则,检查hoursPerDay
是否为负数:
If hoursPerDay < 0 Then hoursPerDay = hoursPerDay + 24