Ok, I tried and tried some more, if someone could push me in a right direction or point out the obvious for me that would be great.
The dates have to be between the years 1900 and 2099, so I was thinking if I could calculate the amount of days from 1900 to each date..I could then compare the difference. But that darn leap year just messes everything up. Below is some code I was working on..but sadly I don't think it will work.
Do I need to do one long loop that looks at every year to see if its normal or leap? Then add 365 or 366 to each running total. I suppose I could do that, but that doesn't seem like the best programming.
const int daysInYear [] = {0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};
const int daysInLeapYear[] = {0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366};
const int daysInMonth [] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int DaysInMonthLeap [] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int dayCaculator (int year, int month, int day)
{
int days;
if ( year %4 == 0 && year !=0 ) //leap year
{
days = year*365 + (year-1)/4 + daysInLeapYear[month] + day ;
}
else // not leap year
{
days = year*365 + (year-1)/4 + daysInYear[month] + day ;
}
return days;