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

前端 未结 10 1594
故里飘歌
故里飘歌 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:32

    Another approach if Monday is the first day, is this:

     Dim today As Date = Date.Today
                    Dim dayDiff As Integer = today.DayOfWeek - DayOfWeek.Monday
                    Dim monday As Date = today.AddDays(-dayDiff)
    
                    dayDiff = DayOfWeek.Saturday - today.DayOfWeek + 1
                    Dim sunday As Date = today.AddDays(dayDiff)
    

提交回复
热议问题