I implemented a function for this:
Code:
/*************************************************\
* dateAdd() *
* Adds a given number of days to a string date *
* Input: *
* ts ->Timestruct, not allocated, hence** *
* achDate ->Datebuffer in format CCYY.MM.DD *
* iAdd ->Number of days to add *
* Output: *
* void *
\*************************************************/
void dateAdd(struct tm **ts, char *achDate, int iAdd){
time_t tBuf(0);
char achBuf[3];
// Init vars
achBuf[2]=0;
time(&tBuf);
*ts=localtime(&tBuf);
// Fetch date from string
memcpy(achBuf, achDate+2, 2); (*ts)->tm_year = atoi(achBuf);
memcpy(achBuf, achDate+5, 2); (*ts)->tm_mon = atoi(achBuf);
memcpy(achBuf, achDate+8, 2); (*ts)->tm_mday = atoi(achBuf);
// Calculate new date
(*ts)->tm_year += 100;
tBuf = mktime(*ts); // Convert to binary time
tBuf += 86400*iAdd; // Add number of days
*ts = localtime(&tBuf); // Update time struct
(*ts)->tm_year -= 100; // I only want a two digit year
}