Function 按周年日计算假期,然后按日历年计算

Function 按周年日计算假期,然后按日历年计算,function,ms-access,parameters,vba,date-arithmetic,Function,Ms Access,Parameters,Vba,Date Arithmetic,我的Access数据库中有一个表单,它根据我的公司政策计算假期。这条规定是,根据你的周年纪念日,在你受雇第一年之后,你可以得到40小时。我于2012年6月9日被录用,2013年6月9日我有40小时的假期 然后,接下来的每一年都滚动到日历年。因此,以我上面的例子来说,我需要使用2013年6月9日至2013年12月31日之间的40个小时,否则我会失去它们,因为2014年1月1日我收到了40个小时 在三年,日历日期,我会得到80小时。2016年1月1日,我有80个小时 在10年,即日历日期,它变为12

我的Access数据库中有一个表单,它根据我的公司政策计算假期。这条规定是,根据你的周年纪念日,在你受雇第一年之后,你可以得到40小时。我于2012年6月9日被录用,2013年6月9日我有40小时的假期

然后,接下来的每一年都滚动到日历年。因此,以我上面的例子来说,我需要使用2013年6月9日至2013年12月31日之间的40个小时,否则我会失去它们,因为2014年1月1日我收到了40个小时

在三年,日历日期,我会得到80小时。2016年1月1日,我有80个小时

在10年,即日历日期,它变为120。我一直在使用的代码从周年纪念日起继续使用,如下所示:

  Function calcVacEarned(asOfDate As Date, HireDate As Date)


  Dim yos As Single
  Dim curryear As Integer
  Dim hireYear As Integer

  curryear = Year(asOfDate)
  hireYear = Year(HireDate)

  yos = (asOfDate - HireDate) / 365.25

  If yos >= 1 Then
    Select Case yos
      Case Is > 10
        calcVacEarned = 120
      Case Is > 3
        calcVacEarned = 80
      Case Is > 1
        calcVacEarned = 40
      Case Else
        calcVacEarned = 0
    End Select
  Else
    If hireYear >= curryear Then
      calcVacEarned = "0"
    Else
      If DateSerial(curryear, Month(HireDate), Day(HireDate)) = asOfDate Then
        calcVacEarned = "40"
      Else
        calcVacEarned = "0"
      End If
    End If
  End If

End Function

我的公司每天都用这个来计算工作时间,可能需要一些帮助。提前谢谢

我希望我已经理解了你的要求。下面是:

Function calcVacEarned(asOfDate As Date, HireDate As Date)  
    Dim anniversary As Boolean
    Dim yos as Integer
    anniversary = False
    yos = Year(asOfDate) - Year(HireDate)

    if Month(HireDate) = Month(asOfDate) And (yos = 1) then
      if Day(HireDate) <= Day(asOfDate) then
        anniversary = True
    end if
    elseif Month(HireDate) < Month(asOfDate) And (yos = 1) then
        anniversary = True 
    end if 

    if anniversary then
        calcVacEarned = 40
    else
        Select Case yos
          Case Is > 10
            calcVacEarned = 120
          Case Is > 3
            calcVacEarned = 80
          Case Is > 1
            calcVacEarned = 40
          Case Else
            calcVacEarned = 0
        End Select
    end if

End Function

很有魅力!!非常感谢你!!