VB.net Get list of weekdays in current month

Hi

What VB.net code would  I use to get a list of the dates for working days from the start of the current month
up to today's date
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
Weekdays or working days? (There is a difference.)
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
Mondays thru Fridays from the 1st of the current month up to today's date:
        Dim WeekDays As New List(Of DateTime)
        Dim today As DateTime = DateTime.Today
        For day As Integer = 1 To today.Day
            Dim dt As New DateTime(today.Year, today.Month, day)
            If dt.DayOfWeek >= DayOfWeek.Monday AndAlso dt.DayOfWeek <= DayOfWeek.Friday Then
                WeekDays.Add(dt)
            End If
        Next

Open in new window

1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Miguel OzSoftware EngineerCommented:
I just improved Tomlinson's code by using the function AddDays:
Public Shared Function GetTotalWorkingDays() As List(Of DateTime)
	Dim weekDays As New List(Of DateTime)()
	Dim today As DateTime = DateTime.Now
	Dim dt As DateTime = today.AddDays(1 - today.Day)
	While dt <= today
		If dt.DayOfWeek >= DayOfWeek.Monday AndAlso dt.DayOfWeek <= DayOfWeek.Friday Then
			weekDays.Add(dt)
		End If
		dt = dt.AddDays(1)
	End While
	Return weekDays
End Function

Open in new window

0
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks
0
käµfm³d 👽Commented:
Would have been nice to get an answer to my question  : \
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.