Search code examples
vb.netdatetimedayofweekweekday

Week of month, month of year,year


I would like to check Week of month, month of year and year but I have a problem with week of month here is code:

Public Class BMW
    Public Shared Function GetWeekNumber() As Integer
        Threading.Thread.Sleep(2000)

        Dim span As TimeSpan = DateTime.Now - New Date(DateTime.Now.Year, 1, 1)
        Return (CInt(span.TotalDays) \ 7) + 1

        If span.TotalDays = 1 Then

            SendKeys.Send("{1}")
            MsgBox(span.TotalDays)

        Else
            MsgBox("chybi1")
end if
end function

Solution

  • Public Shared Function GetWeekNumber(ByVal datum As Date) As Integer
    
        Dim weeknumber = Math.Floor(datum.Day / 7 + +1)
    
        SendKeys.Send(weeknumber)
        Return weeknumber
    
    End Function