MattBaldry
Self Taught, Learn from the Forums
- Local time
- Today, 20:34
- Joined
- Feb 5, 2019
- Messages
- 330
access-programmers.co.uk/forums/showthread.php?t=282642
Following on from the above thread, I am looking for a way to edit the below script to remove lunch breaks and adjust for only working until 1pm Fridays.
Our working hours are as below.
Monday to Thursday - 07:00 to 16:00, Tea Break 10:00 to 10:10, Lunch Break 13:00 to 13:30
Friday - 07:00 to 13:00, Tea Break 10:00 to 10:10
Below is the script version from Grumm that I have been using
I have removed the holiday code part for now, and I have also only asked for the result in minutes as this works better for me.
Anyone who could help me with this would be a superstar as I am stumped.
~Matt
Following on from the above thread, I am looking for a way to edit the below script to remove lunch breaks and adjust for only working until 1pm Fridays.
Our working hours are as below.
Monday to Thursday - 07:00 to 16:00, Tea Break 10:00 to 10:10, Lunch Break 13:00 to 13:30
Friday - 07:00 to 13:00, Tea Break 10:00 to 10:10
Below is the script version from Grumm that I have been using
Code:
Public Function NetWorkHours(dteStart As Date, dteEnd As Date) As String
Dim StDate As Date
Dim StDateD As Date
Dim StDateT As Date
Dim EnDate As Date
Dim EnDateD As Date
Dim EnDateT As Date
Dim WorkDay1Start As Date
Dim WorkDay1end As Date
Dim Result As Long
Dim lHours As Long
Dim lMinutes As Long
Dim MinDay As Integer
StDate = CDate(dteStart)
EnDate = CDate(dteEnd)
WorkDay1Start = DateValue(StDate) + TimeValue("07:30:00")
WorkDay1end = DateValue(StDate) + TimeValue("16:00:00")
StDateD = CDate(Format(StDate, "Short Date"))
EnDateD = CDate(Format(EnDate, "Short Date"))
If StDateD = EnDateD Then
Result = DateDiff("n", StDate, EnDate, vbUseSystemDayOfWeek)
Else
MinDay = (8.5 * 60) 'Number of minutes of a working day. Change this if you change the start and end times.
'Extract the time from the two timestamps
StDateT = Format(StDate, "Short Time")
EnDateT = Format(EnDate, "Short Time")
'Calculate the minutes of the first day and the second one. Don't know what to do yet if the start is after 5pm or the end is before 8am
Result = DateDiff("n", StDateT, TimeValue("16:00:00"), vbUseSystemDayOfWeek)
Result = Result + DateDiff("n", TimeValue("07:30:00"), EnDateT, vbUseSystemDayOfWeek)
'Add 1 day to start date. This is to start the loop to get all the days between both dates.
StDateD = DateAdd("d", 1, StDateD)
Do Until StDateD = EnDateD
'If the date is not a saterday or a sunday we add one day.
If (Weekday(StDateD) > 1) And (Weekday(StDateD) < 7) Then
Result = Result + MinDay
'Check for the holiday. If the date is a holiday, then we remove one day
'If Not IsNull(DLookup("[HolDate]", "Holidays", "[HolDate] = #" & Int(StDateD) & "#")) Then
'Result = Result - MinDay
'End If
End If
StDateD = DateAdd("d", 1, StDateD)
Loop
End If
'lHours = Int(Result / 60)
'lMinutes = Format(Result - (lHours * 60), "00")
'NetWorkHours = Format(lHours, "00") & ":" & Format(lMinutes, "00")
NetWorkHours = Int(Result)
End Function
I have removed the holiday code part for now, and I have also only asked for the result in minutes as this works better for me.
Anyone who could help me with this would be a superstar as I am stumped.
~Matt
Last edited: