Finding the Day of the Week a date starts on
-
Hey, I need to find out what day of the week the first day of each month starts on. Is there a way to do this? Or does anyone have any ideas of how i could write a function in order to find this out? Thanks in advanced Tommy
-
Hey, I need to find out what day of the week the first day of each month starts on. Is there a way to do this? Or does anyone have any ideas of how i could write a function in order to find this out? Thanks in advanced Tommy
I'd recommend that the first step for you would be to take a peek at the availible members of the
DateTime
type in the MSDN documentation. Each member ususally has an example snipit of code, which may prove helpful. In particular, look for theDayOfWeek
property. Using that property, you can easily determine the day of the week for any given date. My very quick and dirty proof of concept for finding the first day of each month:protected override void OnLoad(System.EventArgs ea)
{
DateTime first = DateTime.Parse("01/01/2005");
DayOfWeek day = first.DayOfWeek;
Response.Write(first.ToString("MMMM") + ": " + day.ToString() + "<br />");
for (int index = 0; index < 11; index++)
{
first = first.AddMonths(1);
day = first.DayOfWeek;
Response.Write(first.ToString("MMMM") + ": " + day.ToString() + "<br />");
}
}
Hope that helps. :) --Jesse