|
Public Function AnLeaveDay1(HireDate As Date, Optional EndDate As Date = 0) As Double '精确到天数
Dim i, j As Double
Dim s As Date
Dim y, m, t, d As Integer
If EndDate = 0 Then
EndDate = Date '当前日期
End If
'EndDate = CDate(WorksheetFunction.EoMonth(Date, 0)) '本月的最后一天
y = Year(EndDate) - Year(HireDate)
m = Month(HireDate) - Month(EndDate)
d = Day(HireDate) - Day(EndDate)
i = DateDiff("m", HireDate, EndDate) / 12
t = Year(HireDate) + 1
s = t & "/01/01"
j = DateDiff("d", HireDate, s) / 365
AnLeaveDay1 = 0
If (i >= 21) Or (y = 21 And m > 0) Then
AnLeaveDay1 = 15
Else
If (i > 20 And i < 21) Or (i = 20 And d <= 0) Then
AnLeaveDay1 = 5 * j + 10
Else
If (i >= 11) Or (y = 11 And m > 0) Or (i = 20 And d > 0) Then
AnLeaveDay1 = 10
Else
If (i > 10 And i < 11) Or (i = 10 And d <= 0) Then
AnLeaveDay1 = 5 * j + 5
Else
If (i >= 2) Or (y = 2 And m > 0) Or (i = 10 And d > 0) Then
AnLeaveDay1 = 5
Else
If (i > 1 And i < 2) Or (i = 1 And d <= 0) Then
AnLeaveDay1 = 5 * j
End If
End If
End If
End If
End If
End If
AnLeaveDay1 = Round(AnLeaveDay1, 0)
'AnLeaveDay1 = Int(AnLeaveDay1)
End Function
自定义函数,第一个参数是入职日期,第二个参数是核算截止日期,截止日期为空,则为当前日期,最终可休年假天数四舍五入取整。 |
|