DayPilot Knowledge Base

AJAX Calendar/Scheduling Controls
DayPilot Pro (AJAX Calendar Control)
» DayPilot ASP.NET Calendar
DayPilot Pro (AJAX Monthly Calendar Control)
» DayPilot ASP.NET Monthly Calendar
DayPilot Pro (AJAX Scheduler Control)
» DayPilot ASP.NET Scheduler
DayPilot » Knowledge Base » How to determine the first day of week (ASP.NET)

How to determine the first day of week (ASP.NET)

Last revision: Jun 20, 2014

DayPilot Pro for ASP.NET WebForms contains a helper class that calculates the date of the first day of week from any date.

DayPilotCalendar1.StartDate = DayPilot.Utils.Week.FirstDayOfWeek();

There are several methods/signatures you can call:

The source code:

/// <summary>
/// Helper class for determining first day of week.
/// </summary>
public class Week
{
/// <summary>
/// Gets the first day of this week. Based on current culture.
/// </summary>
/// <returns></returns>
public static DateTime FirstDayOfWeek()
{
return FirstDayOfWeek(DateTime.Today);
}
/// <summary>
/// Gets the first day of a week where day (parameter) belongs. Based on current culture.
/// </summary>
/// <returns></returns>
public static DateTime FirstDayOfWeek(DateTime day)
{
return FirstDayOfWeek(day, Thread.CurrentThread.CurrentCulture.DateTimeFormat.FirstDayOfWeek);
}
/// <summary>
/// Gets the first day of a week where day (parameter) belongs. weekStart (parameter) specifies the starting day of week.
/// </summary>
/// <returns></returns>
public static DateTime FirstDayOfWeek(DateTime day, DayOfWeek weekStarts)
{
DateTime d = day;
while (d.DayOfWeek != weekStarts)
{
d = d.AddDays(-1);
}
return d;
}
/// <summary>
/// Returns Monday of the week where day (parameter) belongs.
/// </summary>
/// <param name="day"></param>
/// <returns></returns>
public static DateTime FirstWorkingDayOfWeek(DateTime day)
{
return FirstDayOfWeek(day, DayOfWeek.Monday);
}
}

Related

How to customize 'Week N' string in the Scheduler header
List of CSS classes used in CssOnly mode (Navigator)
Event Calendar for jQuery (ASP.NET MVC)
How to highight day cells in DayPilot Month using CSS