动态月份的营业日数

问题描述 投票:0回答:1

我需要在Access中报告每个员工有多少加班费。因为一些工作从Mo-Th 10h和Fr 0h工作我不能说

计算8h以上的所有数据。

因此,我需要一个月* 8h的所有工作日,并将其与我按月累计的实际工作时间(已经工作!)进行比较

解决方法:

 SELECT Format([TaetigkeitsDatum],"mmmm yy") AS Monat,  
 tbl_Taetigkeitserfassung.TaetigkeitsPersonalID,  
 Sum(tbl_Taetigkeitserfassung.TaetigkeitsStundenAnzeigen) AS  SummevonTaetigkeitsStundenAnzeigen
 FROM tbl_Taetigkeitserfassung
 GROUP BY Format([TaetigkeitsDatum],"mmmm yy"),  
 tbl_Taetigkeitserfassung.TaetigkeitsPersonalID;

这向我显示格式化的月份(TaetigkeitsDatum),员工(TaetigkeitsPersonalID)和工作时间总和(TaetigkeitsStundenAnzeigen)。

但我不知道如何显示那个月的工作日时间,以便我可以比较和显示加班...

预期解决方案:

1月19日:23天(没有周末,节假日无所谓)* 8h = 184h Mr.X = 186h的工作时间 - > 2h加班

DateDiff不起作用,因为我需要2个日期才能工作,而且还有“仅计算工作日”问题。

ms-access access-vba
1个回答
1
投票

您可以使用此表达式:

WorkDays: ISO_WorkdayDiff(DateSerial(Year([TaetigkeitsDatum]), Month([TaetigkeitsDatum]), 1), DateSerial(Year([TaetigkeitsDatum]), Month([TaetigkeitsDatum]) + 1, 1))

和这样的功能:

Public Function ISO_WorkdayDiff( _
  ByVal datDateFrom As Date, _
  ByVal datDateTo As Date, _
  Optional ByVal booExcludeHolidays As Boolean) _
  As Long

' Purpose: Calculate number of working days between dates datDateFrom and datDateTo.
' Assumes: 5 or 6 working days per week. Weekend is (Saturday and) Sunday.
' May be freely used and distributed.

' 1999-04-23. Gustav Brock, Cactus Data ApS, Copenhagen
' 2000-10-03. Constants added.
'             Option for 5 or 6 working days per week added.
' 2008-06-12. Option to exclude holidays from the count of workdays.

  Const cbytWorkdaysOfWeek  As Byte = 5
  ' Name of table with holidays.
  Const cstrTableHoliday    As String = "tblHoliday"
  ' Name of date field in holiday table.
  Const cstrFieldHoliday    As String = "HolidayDate"

  Dim bytSunday             As Byte
  Dim intWeekdayDateFrom    As Integer
  Dim intWeekdayDateTo      As Integer
  Dim lngDays               As Long
  Dim datDateTemp           As Date
  Dim strDateFrom           As String
  Dim strDateTo             As String
  Dim lngHolidays           As Long
  Dim strFilter             As String

  ' Reverse dates if these have been input reversed.
  If datDateFrom > datDateTo Then
    datDateTemp = datDateFrom
    datDateFrom = datDateTo
    datDateTo = datDateTemp
  End If

  ' Find ISO weekday for Sunday.
  bytSunday = Weekday(vbSunday, vbMonday)

  ' Find weekdays for the dates.
  intWeekdayDateFrom = Weekday(datDateFrom, vbMonday)
  intWeekdayDateTo = Weekday(datDateTo, vbMonday)

  ' Compensate weekdays' value for non-working days (weekends).
  intWeekdayDateFrom = intWeekdayDateFrom + (intWeekdayDateFrom = bytSunday)
  intWeekdayDateTo = intWeekdayDateTo + (intWeekdayDateTo = bytSunday)

  ' Calculate number of working days between the two weekdays, ignoring number of weeks.
  lngDays = intWeekdayDateTo - intWeekdayDateFrom - (cbytWorkdaysOfWeek * (intWeekdayDateTo < intWeekdayDateFrom))
  ' Add number of working days between the weeks of the two dates.
  lngDays = lngDays + (cbytWorkdaysOfWeek * DateDiff("w", datDateFrom, datDateTo, vbMonday, vbFirstFourDays))

  If booExcludeHolidays And lngDays > 0 Then
    strDateFrom = Format(datDateFrom, "yyyy\/mm\/dd")
    strDateTo = Format(datDateTo, "yyyy\/mm\/dd")
    strFilter = cstrFieldHoliday & " Between #" & strDateFrom & "# And #" & strDateTo & "# And Weekday(" & cstrFieldHoliday & ", 2) <= " & cbytWorkdaysOfWeek & ""
    lngHolidays = DCount("*", cstrTableHoliday, strFilter)
  End If

  ISO_WorkdayDiff = lngDays - lngHolidays

End Function
© www.soinside.com 2019 - 2024. All rights reserved.