I recently ran into a situation where I needed to figure out if there were any leap years between two dates.  Although I'm quite sure there is a more elegant way of doing it in C# for purposes of using on an ASP.NET 2.0 page, this is what I came up with and I am quite pleased that it works.  Hopefully somebody will find this useful in the future, as my searching and searching prior to writing this code didn't net me much success.

Why would you want to find out how many leap years are between two dates?  Well, let's say you want to calculate insurance premiums based on a 365 day year.  If you have a leap year, you might have 366 days if the policy started before 2-29 of that year...or if the policy is from 5-1-2000 and goes to 5-1-2004.  The year 2000 does not include the 2-29 date so you are not adjusting the 366 days down to 365...but for the year 2004, you do have to take the extra leap day into consideration when calculating.  This code takes the two dates, starting and ending, figures the total years and days between the dates, and gives a total number of leap year days you must consider between the two.

            DateTime d1 = Convert.ToDateTime(this.txtStartDate.Text);
            DateTime d2 = Convert.ToDateTime(this.txtEndDate.Text);
          
           #region Leap Year Calculations
            //Leap year checker
            int LeapValueToSubtract = 0;
            if (d1.Year == d2.Year)
            {
                //if the same year AND a leap year, we just need to subtract 1 day
                if (DateTime.IsLeapYear(d1.Year) == true && d1.DayOfYear < 60)
                {
                    LeapValueToSubtract++;
                }
            }
            else if (d1.Year != d2.Year)
            {
                if (DateTime.IsLeapYear(d1.Year) == true && d1.DayOfYear < 60)
                {
                    LeapValueToSubtract++;
                }

                int holder = d1.Year;
                holder = holder + (4 - (holder % 4));

                for (int i = 0; i < 10; i++)
                {
                    if (holder < d2.Year)
                    {
                        LeapValueToSubtract++;
                        holder = holder + 4;
                    }
                }
                if (DateTime.IsLeapYear(d2.Year) == true && d2.DayOfYear > 60)
                {
                    LeapValueToSubtract++;
                }

            }
           
this.lblLeapYearDaysToSubtract.Text = Convert.ToString(LeapValueToSubtract);

#endregion