R
RJF
Thanks to this forum, I have the Function below in my database that
calculates the difference between 2 dates.
It calculates how many days between the 2 dates (minus weekend and
holidays), but I need to calculate the Hours and Minutes (i.e. 4:15 is 4
hours and 15 minutes).
If BeginDate is 7/22/2008 8:17:00 AM and EndDate is 7/23/2008 8:17:00 AM,
I need it to show how many hours between
7/22/2008 8:17:00 AM to 7/22/2008 5:00:00 PM
then add those hours to the hours between
7/23/2008 8:00:00 AM and 7/23/2008 8:17:00 AM.
So the result would be 9:00.
If this is something that is very difficult to do, I will be putting it on
the back burner for a while. In other words, no rush but I would appreciate
any help.
I hope I've explained myself clearly enough.
Public Function WorkingDays2(BeginDate As Date, EndDate As Date) As Integer
'....................................................................
' Name: WorkingDays
' Inputs: BeginDate As Date
' EndDate As Date
' Returns: Integer
' Author: Arvin Meyer
' Date: May 5,2002
' Comment: Accepts two dates and returns the number of weekdays between them
' Note that this function has been modified to account for holidays. It
requires a table
' named tblHolidays with a field named HolidayDate.
'....................................................................
On Error GoTo Err_WorkingDays2
Dim intCount As Integer
Dim rst As DAO.Recordset
Dim DB As DAO.Database
Set DB = CurrentDb
Set rst = DB.OpenRecordset("SELECT [HolidayDate] FROM tblHolidays",
dbOpenSnapshot)
BeginDate = BeginDate + 1
'To count BeginDate as the 1st day comment out the line above
intCount = 0
Do While BeginDate <= EndDate
rst.FindFirst "[HolidayDate] = #" & BeginDate & "#"
If Weekday(BeginDate ) <> vbSunday And Weekday(BeginDate ) <> vbSaturday Then
If rst.NoMatch Then intCount = intCount + 1
End If
BeginDate = BeginDate + 1
Loop
WorkingDays2 = intCount
Exit_WorkingDays2:
Exit Function
Err_WorkingDays2:
Select Case Err
Case Else
MsgBox Err.Description
Resume Exit_WorkingDays2
End Select
End Function
Thanks so much.
calculates the difference between 2 dates.
It calculates how many days between the 2 dates (minus weekend and
holidays), but I need to calculate the Hours and Minutes (i.e. 4:15 is 4
hours and 15 minutes).
If BeginDate is 7/22/2008 8:17:00 AM and EndDate is 7/23/2008 8:17:00 AM,
I need it to show how many hours between
7/22/2008 8:17:00 AM to 7/22/2008 5:00:00 PM
then add those hours to the hours between
7/23/2008 8:00:00 AM and 7/23/2008 8:17:00 AM.
So the result would be 9:00.
If this is something that is very difficult to do, I will be putting it on
the back burner for a while. In other words, no rush but I would appreciate
any help.
I hope I've explained myself clearly enough.
Public Function WorkingDays2(BeginDate As Date, EndDate As Date) As Integer
'....................................................................
' Name: WorkingDays
' Inputs: BeginDate As Date
' EndDate As Date
' Returns: Integer
' Author: Arvin Meyer
' Date: May 5,2002
' Comment: Accepts two dates and returns the number of weekdays between them
' Note that this function has been modified to account for holidays. It
requires a table
' named tblHolidays with a field named HolidayDate.
'....................................................................
On Error GoTo Err_WorkingDays2
Dim intCount As Integer
Dim rst As DAO.Recordset
Dim DB As DAO.Database
Set DB = CurrentDb
Set rst = DB.OpenRecordset("SELECT [HolidayDate] FROM tblHolidays",
dbOpenSnapshot)
BeginDate = BeginDate + 1
'To count BeginDate as the 1st day comment out the line above
intCount = 0
Do While BeginDate <= EndDate
rst.FindFirst "[HolidayDate] = #" & BeginDate & "#"
If Weekday(BeginDate ) <> vbSunday And Weekday(BeginDate ) <> vbSaturday Then
If rst.NoMatch Then intCount = intCount + 1
End If
BeginDate = BeginDate + 1
Loop
WorkingDays2 = intCount
Exit_WorkingDays2:
Exit Function
Err_WorkingDays2:
Select Case Err
Case Else
MsgBox Err.Description
Resume Exit_WorkingDays2
End Select
End Function
Thanks so much.