Finding the date of monday in a week with VB.NET

前端 未结 10 1595
故里飘歌
故里飘歌 2020-12-16 12:37

I need to find a way to find the date (DD/MM/YYYY) of the Monday for any week we\'re on.

For example, for this week, monday would be 09/11/2009, and if this were nex

10条回答
  •  独厮守ぢ
    2020-12-16 13:22

    Following on from my comments to Meta-Knight's answer, here is a short function that makes the correction I mention in the comments:

    Public Function GetFirstOfLastWeek() As DateTime
    Dim today As DateTime, daysSinceMonday As Integer
        today = DateTime.Today
        daysSinceMonday = today.DayOfWeek - DayOfWeek.Monday
        If daysSinceMonday < 0 Then
            daysSinceMonday += 7
        End If
        Return today.AddDays(-daysSinceMonday)  
    End Function
    

提交回复
热议问题