- 论坛徽章:
- 0
|
int date_diff(char *date0,char *date1)
{
struct tm tm,tm1;
time_t t;
time_t t1;
char year[5+1],mon[2+1],year1[5+1],mon1[2+1],day[2+1],day1[2+1];
memcpy(year,date0,4);
year[4]='\0';
memcpy(mon,date0+4,2);
mon[2]='\0';
memcpy(day,date0+6,2);
day[2]='\0';
memcpy(year1,date1,4);
year1[4]='\0';
memcpy(mon1,date1+4,2);
mon1[2]='\0';
memcpy(day1,date1+6,2);
day1[2]='\0';
tm.tm_year=atoi(year) - 1900;
tm.tm_mon=atoi(mon) - 1;
tm.tm_mday=atoi(day);
tm1.tm_year=atoi(year1) - 1900;
tm1.tm_mon=atoi(mon1) -1 ;
tm1.tm_mday=atoi(day1);
t=mktime(&tm);
t1=mktime(&tm1);
return ((atoi(year1)-atoi(year)) * 12 + (atoi(mon1)-atoi(mon))) * 30 + atoi(day1) -atoi( day);
} |
|