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

ThisWeekFriday

Returns a DateTime representing the Friday of the current week. Depends on System.Globalization.

Source

public static DateTime ThisWeekFriday(this DateTime dt)
{
  var today = DateTime.Now;
  return new GregorianCalendar().AddDays(today, -((int)today.DayOfWeek) + 5);
}

Example

var friday = DateTime.Now.ThisWeekFriday();

Author: Charles Cherry

Submitted on: 31 aug. 2010

Language: C#

Type: System.DateTime

Views: 5426