Getting start date of the current week

Sheonarayan
Posted by Sheonarayan under C# category on | Points: 40 | Views : 546
To get the start date of the current week, use below function

 public static DateTime StartDateOfCurrentWeek(DateTime input, DayOfWeek startOfWeek)
{
int delta = startOfWeek - input.DayOfWeek;
return input.AddDays(delta);
}

Call this function like this
Response.Write(StartDateOfCurrentWeek(DateTime.Now, DayOfWeek.Sunday));


Here the parameters of this function are Current Date and starting day of the week.

Thanks

Comments or Responses

Login to post response