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

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

    And if your week starts from Monday then you can use something like this:

    DateTime mondayDate = DateTime.Now.AddDays(((DateTime.Now.DayOfWeek == DayOfWeek.Sunday?7: (int)DateTime.Now.DayOfWeek) - 1)*-1);
    
    DateTime sundayDate = DateTime.Now.AddDays(7 - (DateTime.Now.DayOfWeek == DayOfWeek.Sunday?7: (int)DateTime.Now.DayOfWeek ));
    

提交回复
热议问题