Getting the next Monday date (and the one after etc)

Here's a little function that I wrote to return you the Monday's date for this week, next week, etc...

GetNextWeekDates(DayOfWeek.Monday, 0);

Change DayOfWeek.Monday to any day of the week and it will return you the next date on that particular day. The integer represents which date you want to return. 0 means that you want this week's Monday. Set it to 1, then it's the coming Monday. Set it to 2 and you get the date of the Monday after.

        private DateTime GetNextWeekDates(DayOfWeek targetDay, int weekNumber)
        {
            int daysDifference = (int)targetDay - (int)DateTime.Today.DayOfWeek;

            if (daysDifference == 0) weekNumber++;

            DateTime returnDate;

            if (daysDifference < 0)
            {
                returnDate = DateTime.Today.AddDays(daysDifference + 7 + ((weekNumber - 1) * 7));
            }
            else
            {
                returnDate = DateTime.Today.AddDays(daysDifference + ((weekNumber - 1) * 7));
            }

            return returnDate;
        }

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.