kubip486 > 21-02-20, 10:48 AM
ongke0711 > 21-02-20, 09:13 PM
ongke0711 > 21-02-20, 10:06 PM
Option Compare Database
Option Explicit
Public Function TinhTGC(BDTGC As String, KTTGC As String) As Double
On Error GoTo ErrHandler
Dim rsGioNghi As DAO.Recordset
Dim BDGioNghi As Date, KTGioNghi As Date, dtBDTGC As Date, dtKTTGC As Date
Set rsGioNghi = DBEngine(0)(0).OpenRecordset("tblCaLV", dbOpenSnapshot)
If rsGioNghi.EOF And rsGioNghi.BOF Then
MsgBox "Không có du liêu giò làm viêc.", vbExclamation, "Thông báo"
Exit Function
End If
rsGioNghi.MoveFirst
BDGioNghi = rsGioNghi!BDNghiGiuaCa
KTGioNghi = rsGioNghi!KTNghiGiuaCa
rsGioNghi.Close
Set rsGioNghi = Nothing
'Chuyen tu String sang Time
dtBDTGC = TimeValue(BDTGC)
dtKTTGC = TimeValue(KTTGC)
If dtBDTGC < BDGioNghi Then
If dtKTTGC <= KTGioNghi Then
TinhTGC = DateDiff("n", dtBDTGC, Min(dtKTTGC, BDGioNghi))
Else 'dtKTTGC > 12
TinhTGC = DateDiff("n", dtBDTGC, BDGioNghi) + DateDiff("n", KTGioNghi, dtKTTGC)
End If
ElseIf dtBDTGC >= BDGioNghi And dtBDTGC <= KTGioNghi Then
If dtKTTGC > BDGioNghi And dtKTTGC <= KTGioNghi Then
TinhTGC = 0
Else 'dtKTTGC > 12
TinhTGC = DateDiff("n", KTGioNghi, dtKTTGC)
End If
Else 'dtBDTGC > KTGioNghi
TinhTGC = DateDiff("n", dtBDTGC, dtKTTGC)
End If
ErrHandler_Exit:
Exit Function
ErrHandler:
MsgBox "Có loi phát sinh." & vbCrLf & "Mã loi: " & Err.Number & vbCrLf & "Nôi dung lôi: " & Err.Description
Resume ErrHandler_Exit
End Function
kubip486 > 22-02-20, 11:42 AM