In general I use this function,
char *DateDiffer(char *Date, int DayToSub)
{
struct tm time,*tmt;
time_t mtime;
int year,month,date;
char *buffer;
buffer=(char *)malloc(sizeof(char)*10);
if(Date!=NULL)
{
sscanf(Date,"%d-%d-%d",&year,&month,&date);
}
memset((char*)(&time),0,sizeof(struct tm));
time.tm_year=year-1900;
time.tm_mon=month-1;
time.tm_mday=date-DayToSub;
mtime=mktime(&time);
tmt=localtime(&mtime);
sprintf(buffer,"%04d-%02d-%02d\n",(tmt->tm_year+1900),(tmt->tm_mon+1),tmt->tm_mday);
return buffer;
}