int date_value(int day, int month, int year) {
year -= 1900;
int totval = year * 365;
totval += (year-1)/4;
totval -= (year-1)/100;
totval += (year+900)/1000;
switch(month) {
case(12): totval += 30;
case(11): totval += 31;
case(10): totval += 30;
case(9) : totval += 31;
case(8) : totval += 31;
case(7) : totval += 30;
case(6) : totval += 31;
case(5) : totval += 30;
case(4) : totval += 31;
case(3) : totval += 28;
if ( ((year%4)==0)&&(((year%100)!=0)||((year-100)%1000)==0) )
totval++;
case(2) : totval += 31;
}
totval +=day;
return totval;
}
Here's my take on it:
// take
int date_value(int day, int month, int year) {
year -= 1900; //not sure
int totval = year * 365; // calculating the year total
totval += (year-1)/4; //not sure
totval -= (year-1)/100; //not sure
totval += (year+900)/1000; //not sure
switch(month) { // case 1 is the number of days in January, case 2 is the number of
case(12): totval += 30; // days in February, etc.
case(11): totval += 31;
case(10): totval += 30;
case(9) : totval += 31;
case(8) : totval += 31;
case(7) : totval += 30;
case(6) : totval += 31;
case(5) : totval += 30;
case(4) : totval += 31;
case(3) : totval += 28;
if ( ((year%4)==0)&&(((year%100)!=0)||((year-100)%1000)==0) ) //test if its a leap year
totval++; //adds days from previous months to
case(2) : totval += 31; // entered date
}
totval +=day; // not sure
return totval; // returns total
}
[/code]