Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List all weekdays of a month(variable) 1

Status
Not open for further replies.

Blondie96

Programmer
Aug 12, 2004
119
0
0
US
I need to produce a list of the dates i.e. 4/18/05...
of the weekdays of a month I pass as a variable.

Does anyone know how I could produce this?

Thanks

Tamra
 
I don't know of a neat way but the DatePart function with a "w" parameter will give you the day of the week of a given date so you could loop through the month working out whether each date is a weekday or weekend.

An alternative would be to determine the day of the week of the first of the month then use some simple arithmetic to work out where the weekend's fall. If first is a Tuesday then first+1, +2, +3, +6, +7 etc are all weekdays.

Geoff Franklin
 
Tamra,
There are probably really slick ways to do this. I don't know them [smile]. Here is a way to do what you want. It assumes that you pass the month name and year in separate fields. If you're passing a date in the middle of the month, you will have to fiddle with the dateparts a little bit in order to get myDate set to the first day of the month in question.

Write back if this is too oblique...

Code:
Private Sub WeekDays()
Dim strMon As String
Dim strYear As String
Dim myDate As Date
Dim intMon As Integer

strMon = "April"  'Assuming you're passing the month and year, somehow...
strYear = "2005"
myDate = CDate(strMon & " 01, " & strYear)  'Date set to first day of month
intMon = DatePart("M", myDate)  'Store the month

Do Until DatePart("M", myDate) <> intMon
  Select Case DatePart("w", myDate)   '"w" is day of week
    Case 2, 3, 4, 5, 6   'Weekdays
      Debug.Print myDate, DatePart("w", myDate)
  End Select
  myDate = DateAdd("D", 1, myDate)  'Add 1 day until month changes
Loop

End Sub

Tranman
 
Tranman,

Thank you. This looks like just what I need. I will be passing a month, stringing the first day and then looking from there (I won't be dealing with the middle of the month stuff....famous last words though).

I doubt the code is "too oblique" but I will be giving it a try shortly.

Thanks again,

Tamra
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top