Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,888 questions

51,815 answers

573 users

How to calculate the number of weekdays in the current year with VB.NET

1 Answer

0 votes
Imports System

Public Class WeekdayCalculator
	Public Shared Sub Main()
        Dim year As Integer = DateTime.Now.Year
        Dim weekdayCount As Integer = CountWeekdaysInYear(year)
        Console.WriteLine($"Number of weekdays in {year}: {weekdayCount}")
    End Sub

    Private Shared Function CountWeekdaysInYear(ByVal year As Integer) As Integer
        Dim weekdayCount As Integer = 0
        Dim dt As DateTime = New DateTime(year, 1, 1)

        While dt.Year = year

            If dt.DayOfWeek <> DayOfWeek.Saturday AndAlso dt.DayOfWeek <> DayOfWeek.Sunday Then
                weekdayCount += 1
            End If

            dt = dt.AddDays(1)
        End While

        Return weekdayCount
    End Function
End Class



' run:
'
' Number of weekdays in 2025: 261
'

 



answered Feb 17, 2025 by avibootz

Related questions

1 answer 110 views
1 answer 67 views
1 answer 68 views
2 answers 67 views
2 answers 63 views
1 answer 71 views
1 answer 91 views
...