DateTime question in VB.NET

前端 未结 3 1593
孤街浪徒
孤街浪徒 2020-12-21 18:09

Ok, so I need to find the date of Monday this week programmatically.

For example, for this week Monday was on the 9th, so the date I need is: 09/11/2009

And

3条回答
  •  独厮守ぢ
    2020-12-21 18:36

    Return givenDate.AddDays(1 - CType(IIf((givenDate.DayOfWeek = DayOfWeek.Sunday), 7, givenDate.DayOfWeek), Double))
    

    If givenDate is a Sunday, counts back to the preceding Monday. Includes a CType to cast the IIf result to a Double to work with Option Strict On.

提交回复
热议问题