Click here to Skip to main content
15,882,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How can I get the date of the next monday from current day? Please advice.
Posted
Updated 4-Aug-21 10:12am
Comments
Afzaal Ahmad Zeeshan 29-Mar-15 21:23pm    
You do not get the next Monday from today, instead you can get the first Monday of next month and then return it.

 
Share this answer
 
You could use the Property
DateTime.DayOfWeek
to get the current day and work out how many days until the next Monday. This enumeration start at 0 for Sunday.
 
Share this answer
 
// REFER: https://social.msdn.microsoft.com/Forums/vstudio/en-US/82d94a16-baf6-4e7d-be70-b3c879b769c2/how-can-i-get-the-date-of-the-next-monday-from-the-currentday?forum=csharpgeneral

 public static DateTime GetNextWeekday(DateTime start, DayOfWeek dayOfWeek)
 {
    // The (... + 7) % 7 ensures we end up with a value in the range [0, 6]
    int daysToAdd = ((int)dayOfWeek - (int)start.DayOfWeek + 7) % 7;
    return start.AddDays(daysToAdd);
 }

 public static DateTime GetNextDeliveryDay(DayOfWeek dayOfWeek)
 {
     return GetNextWeekday(DateTime.UtcNow.Date.AddDays(1), dayOfWeek);
 }
 
Share this answer
 
Comments
CHill60 5-Aug-21 4:28am    
You do realise that this is the exact same code that was on the link in Solution 1 posted 6 years ago. I hope you also realise that some members will see this as plagiarism.
Stick to answering newer posts where the OP still needs help and try to ensure that you are brining something new to the thread

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900