Hi Guys
I need help on a problem I am having with the datediff function.
I have a table in my db which has 4 date fields:
DateRequested
DateReceived
DateReferred
DateOfAdmission
I have created the following module to work out weekdays (not weekends):
----------------------------------------------------------------------
Option Compare Database
Function DateDiffW(BegDate, EndDate)
Const SUNDAY = 1
Const SATURDAY = 7
Dim NumWeeks As Integer
If Not IsNull(BegDate) Then
If Not IsNull(EndDate) Then
If BegDate > EndDate Then
DateDiffW = 0
Else
Select Case Weekday(BegDate)
Case SUNDAY: BegDate = BegDate + 1
Case SATURDAY: BegDate = BegDate + 2
End Select
Select Case Weekday(EndDate)
Case SUNDAY: EndDate = EndDate - 2
Case SATURDAY: EndDate = EndDate - 1
End Select
NumWeeks = DateDiff("ww", BegDate, EndDate)
DateDiffW = NumWeeks * 5 + Weekday(EndDate) - Weekday(BegDate)
End If
End If
End If
End Function
-------------------------------------------------------------------
I have a query which works out the difference between any of these dates and it works fine.
My problem is that I would like know what the date would be 28 days from the DateRequested only including the weekdays.
I have tried entering DateDiffW + 28 in the query but it doesnt work.
Can anyone help me with this please.
Many Thanks in advance
Daz
I need help on a problem I am having with the datediff function.
I have a table in my db which has 4 date fields:
DateRequested
DateReceived
DateReferred
DateOfAdmission
I have created the following module to work out weekdays (not weekends):
----------------------------------------------------------------------
Option Compare Database
Function DateDiffW(BegDate, EndDate)
Const SUNDAY = 1
Const SATURDAY = 7
Dim NumWeeks As Integer
If Not IsNull(BegDate) Then
If Not IsNull(EndDate) Then
If BegDate > EndDate Then
DateDiffW = 0
Else
Select Case Weekday(BegDate)
Case SUNDAY: BegDate = BegDate + 1
Case SATURDAY: BegDate = BegDate + 2
End Select
Select Case Weekday(EndDate)
Case SUNDAY: EndDate = EndDate - 2
Case SATURDAY: EndDate = EndDate - 1
End Select
NumWeeks = DateDiff("ww", BegDate, EndDate)
DateDiffW = NumWeeks * 5 + Weekday(EndDate) - Weekday(BegDate)
End If
End If
End If
End Function
-------------------------------------------------------------------
I have a query which works out the difference between any of these dates and it works fine.
My problem is that I would like know what the date would be 28 days from the DateRequested only including the weekdays.
I have tried entering DateDiffW + 28 in the query but it doesnt work.
Can anyone help me with this please.
Many Thanks in advance
Daz