Before I reinvent the wheel: does anyone have a simple formula to calculate the DateTime for the next Monday? I tried some googling but found nothing simple or even working.
July 5. You’re welcome.
Seriously, use ( 9 - DateTime.Now.DayOfWeek ) mod 7 to get the number of days, then add that back to Now as an interval.
Note if the current date is Monday, it will return the current date.
it search for next monday and return the date with same time.
Public Function NextMonday(d As DateTime) As DateTime Do If d.DayOfWeek = 2 Then Exit 'on Monday, 1=Sunday, 7=Saturday d = d + New DateInterval(0,0,1) 'one Day more Loop Return d End Function
Thanks, that also a good solution.
yes but can be 7x slower ?
Speed is not a consideration here because I’m just showing something on the UI.