12,396,951 members (38,893 online)
Rate this:
See more:
hi everyone
please I want to help me in finding function return number weekend in month with access database according to calendar in computer
for example if month is june the function will return 5
if month is july the funtion will return 4 and so on
thank you
Posted 21-Jun-12 3:26am
firaso395
Sandeep Mewara 21-Jun-12 9:51am

What have you tried so for?
firaso 21-Jun-12 12:11pm

I tried the following
varWeekendDays = (DateDiff(Interval:="ww", _
date1:=startDate, _
date2:=endDate) _
* ncNumberOfWeekendDays) _
+ IIf(DatePart(Interval:="w", _
Date:=startDate) = vbSunday, 1, 0) _
+ IIf(DatePart(Interval:="w", _
Date:=endDate) = vbSaturday, 1, 0)

Rate this:

Rate this:

## Solution 2

Test it:
```Option Compare Database
Option Explicit

Sub Test()
Dim dCurDate As Date, dStartDate As Date, dEndDate As Date

dStartDate = CDate("2012-10-16")
dEndDate = CDate("2013-04-15")

dCurDate = dStartDate
Do While dCurDate < dEndDate
MsgBox Format(dCurDate, "MMMM yyyy") & " has " & GetCountOfWeeks(dCurDate) & " weeks!", vbInformation, "Message..."
Loop

End Sub

Function GetCountOfWeeks(dInitialDate As Date) As Integer
Dim retVal As Integer
Dim dCurDate As Date, dStartDate As Date, dEndDate As Date

retVal = 0
dStartDate = GetFirstDayInMonth(dInitialDate)
dCurDate = dStartDate
dEndDate = GetLastDayInMonth(dInitialDate)
Do While dCurDate < dEndDate
If Weekday(dCurDate) = vbSunday Then retVal = retVal + 1
Loop
GetCountOfWeeks = retVal

End Function

Function GetFirstDayInMonth(dDate As Date) As Date
GetFirstDayInMonth = DateSerial(Year(dDate), Month(dDate), 1)
End Function

Function GetLastDayInMonth(dDate As Date) As Date
GetLastDayInMonth = DateSerial(Year(dDate), Month(dDate) + 1, 1 - 1)
End Function```

Top Experts
Last 24hrsThis month
 OriginalGriff 155 Karthik Bangalore 150 Richard MacCutchan 135 BillWoodruff 95 ppolymorphe 85
 OriginalGriff 6,138 Karthik Bangalore 2,497 ppolymorphe 2,445 F-ES Sitecore 1,877 Richard MacCutchan 1,812