Following code will give you the week start date on passing any date.
private DateTime getWeekStartDate(DateTime weekDate)
{
DateTime currentWeekStartDate = weekDate;
string StartDay = "1" // You can set any day as start day of the week
// 1 for monday, 2 for tuesday and so on
while (!StartDay.ToLower().Equals(currentWeekStartDate.DayOfWeek.ToString().ToLower()))
{
currentWeekStartDate = currentWeekStartDate.Subtract(new TimeSpan(1, 0, 0, 0));
}
return currentWeekStartDate
}
Hope this helps, thanks
No comments:
Post a Comment