You need to replace your check for "Saturday" with a check for 2nd Saturday in a year...e.g.
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
CalendarDay dateToCheck = e.Day;
if(Is2ndSaturday(dateToCheck.Date))
{
e.Cell.BackColor = Color.Red;
}
}
Setting and checking
flag
is fairly pointless but if you wanted to speed things up you could skip the test each year once you've already highlighted the date for that year.
The function
Is2ndSaturday
below takes a fairly "brute force" approach. I start with January 1st for the year being displayed, checks to see if it (1st Jan) is already a Saturday and if not just increment a working date until it finds a Saturday. That will be the first Saturday, so once you've found it, just add 7 days to find the second Saturday.
Here I've just compared the date of the second Saturday to the input date and return a bool if they match. You could change it to return the date instead.
private bool Is2ndSaturday(DateTime dtIn)
{
DateTime dt1 = new DateTime(dtIn.Year, 1, 1);
while (dt1.DayOfWeek != DayOfWeek.Saturday)
{
dt1.AddDays(1.0);
}
dt1.AddDays(7);
return (dtIn.CompareTo(dt1) == 0) ? true : false;
}