View Single Post
Old Dec 8th, 2005, 9:42 PM   #2
juliocarlosmg
Unverified User
 
juliocarlosmg's Avatar
 
Join Date: Nov 2004
Location: caribe
Posts: 5
Rep Power: 0 juliocarlosmg is on a distinguished road
Lightbulb solved(i think)

a couple of months ago i had to make a Date class for the school. here you have something that may help you. perhaps you will need to change something but the idea is correct and its work. it's very simple, so, don't need any explanations.

int CountLeapYears(int startingYear, int endingYear)
{
if (startingYear < 1 || startingYear > 9999 || endingYear < 1 || endingYear > 9999)
throw new ArgumentOutOfRangeException();
if (startingYear == endingYear)
throw new ArgumentException();
int ydiff = startingYear - endingYear;
if (ydiff < 0)
ydiff = -ydiff;
return ydiff / 4 - ydiff / 100 + ydiff / 400;
}

int CountDays(DateTime dt1, DateTime dt2)
{
if (dt1 == null || dt2 == null)
throw new ArgumentNullException();
if (dt1.Year >= dt2.Year)
throw new ArgumentException();
int ydiff = dt2.Year - dt1.Year;
int c = ydiff * 365 + CountLeapYears(dt1.Year, dt2.Year) - dt1.DayOfYear + dt2.DayOfYear;
}
juliocarlosmg is offline   Reply With Quote