private DateTime[] weekByDay(DateTime date)
{
DateTime[] week = new DateTime[5];
while (date.DayOfWeek != DayOfWeek.Monday) //while day is not monday
{
date = date.AddDays(-1); //substract 1 day to date
}
week[0] = date; //add the current day (monday), to the array
for (int i = 1; i < 5; i++) //add the next day till Friday
{
date = date.AddDays(1);
week[i] = date;
}
Console.WriteLine("MONDAY was " + week[0]);
Console.WriteLine("TUESDAY was " + week[1]);
Console.WriteLine("WEDNESDAY was " + week[2]);
Console.WriteLine("THURSDAY was " + week[3]);
Console.WriteLine("FRIDAY was " + week[4]);
return week;
}
solved Get days of a week, by a day of the month