How to know witch are the weekend days between two dates

G

Guest

I have to make a list of every weekend days between two dates.

Example (dd/mm/yyyy):
Field1: 01/01/2007
Field2: 15/01/2007

The result (on a listbox) I want are all the weekend days between those dates:
06/01/2007
07/01/2007
13/01/2007
14/01/2007

Any help?
 
N

NthDegree via AccessMonster.com

Assuming i have two fields on a form that contain the beginning and ending
dates (FirstDay, LastDay), a listbox (list0) and a command button to compute
them, the code would looke like this.

Private Sub Command2_Click()

Dim strday As String
Dim intIndex As Integer
Dim intNbrDays As Integer
Dim newdate As Date

List0.RowSource = ""
intNbrDays = DateDiff("d", FirstDay, LastDay)
For intIndex = 0 To intNbrDays
newdate = FirstDay + intIndex
strday = DatePart("w", newdate)
If strday = 1 Or strday = 7 Then
List0.AddItem Item:=newdate
End If
Next intIndex
End Sub
 
B

Bill

You can use code such as this to determine the date value of the
Sunday prior to the current date:

SunDVal = CLng(Date) - Weekday(Date) + 1

If you're familiar/comfortable using date values based on the epoch
used by Access (Windows & Office actually), you can then add and
or subtract 7 to move from one weekend to another.

Hope this gets you started.

Bill
 
G

Guest

This is air code but should pull a list of Week-end dates between 2 inputs

Function FindWeekEnd(dtDate1 As Variant, dtDate2 As Variant) As Variant

intDays = DateDiff("d", dtDate1, dtDate2)

dtDate = dtDate1
For I = 1 To intDays - 1 Step 1
dtDate = DateAdd("d", 1, dtDate)
If Weekday(dtDate) = vbSaturday Or Weekday(dtDate) = vbSunday Then
FindWeekEnd = FindWeekEnd & "," & dtDate
End If
Next I

FindWeekEnd = Right(FindvWeekEnd, Len(FindWeekEnd) - 1)

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top