Don't know if the following could be of any help, at least for the second part of your requirement (get the number of days from your birthdate to the current date):
This function will return the number of days from 1900-1-1:
int countDaysFrom1900(int y, int m, int d) {
// The sum of days, equivalent to your msc array
int days[] = {0, 31, days[1] + 28, days[2] + 31, days[3] + 30, days[4] + 31, days[5] + 30, days[6] + 31, days[7] + 31, days[8] + 30, days[9] + 31, days[10] + 30, days[11] + 31};
// Offset the day value if the year is a leap year
// The: "(!(y % 400) || ((y % 100) && !(y % 4)))" thing is checking the leap year
int offset = m > 2 && (!(y % 400) || ((y % 100) && !(y % 4))) ? 1 : 0;
// Calculate the number of transcurred days
return y -= 1901, ((y + 1) * 365 + (y / 4) - (y / 100) + ((y + 1900) / 400) - 4 + days[m - 1] + offset + d - 1);
}
Here is an usage example:
int main() {
std::cout << countDaysFrom1900(1900, 1, 1) << std::endl;
std::cout << countDaysFrom1900(1900, 1, 2) << std::endl;
std::cout << countDaysFrom1900(1901, 1, 1) << std::endl;
std::cout << countDaysFrom1900(2013, 10, 13) << std::endl;
// Some birthdate
int daysFromBirthdate = countDaysFrom1900(1982, 4, 27);
int currentDate = countDaysFrom1900(2013, 10, 13);
std::cout << "There are " << (currentDate - daysFromBirthdate) << " days from birthdate" << std::endl;
return 0;
}
Prints:
0
1
365
41558
There are 11492 days from birthdate