我想得到博士(3)和博士(4)之间的时间差异
Sub workinghours()
cmd = New SqlCommand("SELECT * FROM dtrtable WHERE EmployeeID = '" & Me.TextBox3.Text & "' AND TimeOUT is not NULL", con)
dr = cmd.ExecuteReader
While dr.Read
gettimein = dr(3)
gettimeout = dr(4)
While gettimein < gettimeout
gethours = gethours + 1
gettimein = gettimein + 1
End While
gettimein = Nothing
gettimeout = Nothing
End While
dr.Close()
Me.TextBox8.Text = gethours
gethours = Nothing
End Sub
答案 0 :(得分:1)
您可以使用TimeSpan
类,只需删除AM/PM
部分。
Dim ts1 = TimeSpan.Parse(dr(3).ToString.Replace(" AM", "").Replace(" PM", ""))
Dim ts2 = TimeSpan.Parse(dr(4).ToString.Replace(" AM", "").Replace(" PM", ""))
If ts1 > ts2 Then
'do something
End If
答案 1 :(得分:-1)
我已经解决了,现在我的问题是如果timediff是&gt;正在加班8.这是我的代码..
Sub eto() cmd = New SqlCommand("select * from dtrtable where EmployeeID = '" & Me.TextBox3.Text & "'AND TimeOUT is not NULL ", con) dr = cmd.ExecuteReader While dr.Read gethours = DateDiff(DateInterval.Hour, dr(3), dr(4)) While dr.Read gethours = gethours + DateDiff(DateInterval.Hour, dr(3), dr(4)) End While End While dr.Close() Me.TextBox9.Text = getothours Me.TextBox8.Text = gethours End Sub