Количество дней между двумя датами?

IT IT
Здравствуйте, 4mbi3nt, Вы писали:

4>спасибо, но меня интересует, как зто реализуется на более низком уровни.


Ну тогда вот очередное извратство на плюсах:

static int days[12+1] = {
    0,
    31,
    31+ 28,
    31+ 28+ 31,
    31+ 28+ 31+ 30,
    31+ 28+ 31+ 30+ 31,
    31+ 28+ 31+ 30+ 31+ 30,
    31+ 28+ 31+ 30+ 31+ 30+ 31,
    31+ 28+ 31+ 30+ 31+ 30+ 31+ 31,
    31+ 28+ 31+ 30+ 31+ 30+ 31+ 31+ 30,
    31+ 28+ 31+ 30+ 31+ 30+ 31+ 31+ 30+ 31,
    31+ 28+ 31+ 30+ 31+ 30+ 31+ 31+ 30+ 31+ 30,
    31+ 28+ 31+ 30+ 31+ 30+ 31+ 31+ 30+ 31+ 30+ 31
};

static int dayS[12+1] = {
    0,
    31,
    31+ 29,
    31+ 29+ 31,
    31+ 29+ 31+ 30,
    31+ 29+ 31+ 30+ 31,
    31+ 29+ 31+ 30+ 31+ 30,
    31+ 29+ 31+ 30+ 31+ 30+ 31,
    31+ 29+ 31+ 30+ 31+ 30+ 31+ 31,
    31+ 29+ 31+ 30+ 31+ 30+ 31+ 31+ 30,
    31+ 29+ 31+ 30+ 31+ 30+ 31+ 31+ 30+ 31,
    31+ 29+ 31+ 30+ 31+ 30+ 31+ 31+ 30+ 31+ 30,
    31+ 29+ 31+ 30+ 31+ 30+ 31+ 31+ 30+ 31+ 30+ 31
};

bool isLeapYear(int year)
{
    return (year % 4) == 0 && (year % 100) != 0 || (year % 400) == 0;
}

int getDays(int year,int mon,int day)
{
    return year * 365 +
           (year + 3) / 4 - (year + 99) / 100 + (year + 399) / 400 +
           (isLeapYear(year)? dayS: days)[mon-1] + day - 1;
}

void main()
{
    printf("%d",getDays(1990,2,3) - getDays(1984,10,27));
}