MS Access Query - Total Week Hours Worked
looking for some access query help. Im trying to make a total hours worked in a week query. TotalHours: (([FinishAM]-[StartAM]+[FinishPM]-[StartPM])*24 & " Hours") Here's the query for the daily hours worked.. Im quite new to access. cheers.
You can use: ' Specify begin and end time of daily working hours. Const cdatWorkTimeStart As Date = #8:00:00 AM# Const cdatWorkTimeStop As Date = #4:00:00 PM# Const cbytWorkdaysOfWeek As Byte = 5 Dim TotalHours As Integer TotalHours = DateDiff("h", cdatWorkTimeStart, cdatWorkTimeStop) * cbytWorkdaysOfWeek For an extended count of hours for any count of days, you can use the full function here: Public Function ISO_WorkTimeDiff( _ ByVal datDateTimeFrom As Date, _ ByVal datDateTimeTo As Date, _ Optional ByVal booNoHours As Boolean) _ As Long ' Purpose: Calculate number of working minutes between date/times datDateTimeFrom and datDateTimeTo. ' Assumes: 5 or 6 working days per week. Weekend is (Saturday and) Sunday. ' Returns: "Working minutes". Divide by 60 to obtain working hours. ' Limitation: Does not count for public holidays. ' ' May be freely used and distributed. ' 2001-06-26. Gustav Brock, Cactus Data ApS, Copenhagen ' ' If booNoHours is True, time values are ignored. ' Specify begin and end time of daily working hours. Const cdatWorkTimeStart As Date = #8:00:00 AM# Const cdatWorkTimeStop As Date = #4:00:00 PM# Const cbytWorkdaysOfWeek As Byte = 5 Dim bytSunday As Byte Dim intWeekdayDateFrom As Integer Dim intWeekdayDateTo As Integer Dim datTimeFrom As Date Dim datTimeTo As Date Dim lngDays As Long Dim lngMinutes As Long Dim lngWorkMinutesDaily As Long ' No special error handling. On Error Resume Next If DateDiff("n", datDateTimeFrom, datDateTimeTo) <= 0 Then ' Nothing to do. Return zero. Else ' Calculate number of daily "working minutes". lngWorkMinutesDaily = DateDiff("n", cdatWorkTimeStart, cdatWorkTimeStop) ' Find ISO weekday for Sunday. bytSunday = Weekday(vbSunday, vbMonday) ' Find weekdays for the dates. intWeekdayDateFrom = Weekday(datDateTimeFrom, vbMonday) intWeekdayDateTo = Weekday(datDateTimeTo, vbMonday) ' Compensate weekdays' value for non-working days (weekends). intWeekdayDateFrom = intWeekdayDateFrom + (intWeekdayDateFrom = bytSunday) intWeekdayDateTo = intWeekdayDateTo + (intWeekdayDateTo = bytSunday) ' Calculate number of working days between the weeks of the two dates. lngDays = (cbytWorkdaysOfWeek * DateDiff("w", datDateTimeFrom, datDateTimeTo, vbMonday, vbFirstFourDays)) ' Add number of working days between the two weekdays, ignoring number of weeks. lngDays = lngDays + intWeekdayDateTo - intWeekdayDateFrom - (cbytWorkdaysOfWeek * (intWeekdayDateTo < intWeekdayDateFrom)) If Not booNoHours = True Then ' Extract begin and stop hour (time) for the working period. datTimeFrom = TimeSerial(Hour(datDateTimeFrom), Minute(datDateTimeFrom), Second(datDateTimeFrom)) datTimeTo = TimeSerial(Hour(datDateTimeTo), Minute(datDateTimeTo), Second(datDateTimeTo)) ' Adjust times before or after daily working hours to boundaries of working hours. If DateDiff("n", datTimeFrom, cdatWorkTimeStart) > 0 Then datTimeFrom = cdatWorkTimeStart ElseIf DateDiff("n", datTimeFrom, cdatWorkTimeStop) < 0 Then datTimeFrom = cdatWorkTimeStop End If If DateDiff("n", datTimeTo, cdatWorkTimeStart) > 0 Then datTimeTo = cdatWorkTimeStart ElseIf DateDiff("n", datTimeTo, cdatWorkTimeStop) < 0 Then datTimeTo = cdatWorkTimeStop End If ' Calculate number of working minutes between the two days, ignoring number of days. lngMinutes = DateDiff("n", datTimeFrom, datTimeTo) End If ' Calculate number of working minutes between the two days using the workday count. lngMinutes = lngMinutes + (lngDays * lngWorkMinutesDaily) End If ISO_WorkTimeDiff = lngMinutes End Function
Access Report ignores DISTINCROW in query
checking whether field in table has space or comma - MS-Access
Forms and Subforms in Access 2003
EasyPHP connecting to MS Access
Access 2010 Runtime question
Access Input textbox on Data Access page with only select enabled to allow filter by searchs
Microsoft Access Query through VBA gets repeated?
What sort of functionality can I expect from exporting a Microsoft Access 2007 Database to a WSS 3.0 site?
query muliple fields with multiple values
Force OpenCurrentDatabase to use Access 2003
ACCESS/VBA: How to create a ON/OFF type switch to allow record modification on a form?
dsn for ms access 2003 in windows 7
How can I find all the MS Access security groups in VBA
Drop all connection to MS Access Database using ADO.NET
Import MS Access to CSV on Mac programmatically