The number of days from 01/01/1800 to 11/21/2004 is 74833. I used this little code below. Interesting as far as algorithms are concerned, but the span needs to be more than a year to trap leap years correctly.
[php]// Find the number of days between given dates mm/dd/yyyy
// algorithm does not work properly with leap years, if the
// span is less than a year
// right number for 01/01/2004 to 01/01/2005 (366 days)
// wrong number for 01/01/2004 to 12/31/2004 (364 days)
// right number for 01/01/1900 to 01/01/2000 (36524 days)
// right number for 01/01/2000 to 01/01/2100 (36525 days)
// since 2000 was a leap year and 1900 was not
// (years ending with 00 have to be divisible by 400 to leap)
// Code modified to compile with Pelles C (dns)
#include <stdio.h> // printf(), scanf()
long days(int sm, int sd, int sy, int em, int ed, int ey);
long factor(int mm, int dd, int yy);
int main(void)
{
int sm, sd, sy; // starting date
int em, ed ,ey;
long old;
printf("\n Calculate days between two dates ...");
printf("\n\n Enter starting date in mm/dd/yyyy format: ");
scanf("%d/%d/%d",&sm,&sd,&sy);
printf("\n Enter ending date in mm/dd/yyyy format: ");
scanf("%d/%d/%d",&em,&ed,&ey);
old = days(sm,sd,sy,em,ed,ey);
printf("\n There are %ld days between %d/%d/%d and %d/%d/%d\n",
old,sm,sd,sy,em,ed,ey);
getchar(); // wait
getchar(); // 2nd wait needed
return 0;
}
//
// returns number of days between start and end dates
// span has to be more than a year to catch leap years properly
//
long days(int sm, int sd, int sy, int em, int ed, int ey)
{
long fac1, fac2, elap;
fac1 = factor(sm, sd, sy);
fac2 = factor(em, ed, ey);
elap = fac2 - fac1;
return (elap);
}
long factor(int mm, int dd, int yy)
{
long xx;
xx = 365 * yy + dd + 31 * (mm - 1);
if (mm < 3)
xx = xx + ((yy -1)/4) - (.75 * ((yy - 1)/100)+1);
else
xx = xx - (.4 * mm + 2.3) + (yy / 4) - (((.75 * (yy / 100) + 1)));
return (xx);
}
[/php]