c:date:datime

C++ Reference

datime

Example:

int datime(int *year,int *mon, int *day)
{
    int i,days;
    int flg,tbl[]={0,31,28,31,30,31,30,31,31,30,31,30,31};

    if (*year%4 == 0) {
        if (*year%400 == 0) flg=1;
        else if (*year%100 == 0) flg=0;
        else flg=1;
    }
    tbl[2]+=flg;
    if (*day < 1) *day=1;
    if (*mon < 1) *mon=1;
    if (*day > tbl[*mon]) {*day=1;(*mon)++ ;}
    if (*mon > 12) {*mon=1;(*year)++;}
    days=*day-1;for (i=1;i < *mon;i++) days+=tbl[i];
    return days;
}