Jump to content

Find the last Sunday of each month: Difference between revisions

m
Line 804:
*/
// The updated code
int daysOffestdaysOffset = date.DayOfWeek - dayOfWeek; // take the offset to subtract directly instead of looping
if (daysOffestdaysOffset < 0) daysOffestdaysOffset += 7; // if the code is negative, we need to normalize them
date = date.AddDays(-daysOffestdaysOffset ); // now just add the days offset
Console.WriteLine(date.ToString("yyyy-MM-dd"));
}
Cookies help us deliver our services. By using our services, you agree to our use of cookies.