ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

GetSaturday

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

Source

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.

Author: Brent Coppock (original by Charles Cherry)

Submitted on: 23 nov. 2017

Language: C#

Type: DateTime

Views: 4266