GetSaturday

public static DateTime GetSaturday(this DateTime dt)
        {
            DateTime date = new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second);
            return new GregorianCalendar().AddDays(date, -((int)date.DayOfWeek) + 6);
        }
Example:
This code will provide the Saturday DateTime from the week of DateTime object the extension method is called from.

Description

This code will provide the Sunday DateTime from the week of DateTime object the extension method is called from.

Details

Double click on the code to select all.

 

;