I'm porting a C app from Solaris to RedHat, and this function does not work very well on RedHat (and I need your help determing why):
int toTimestamp (const char *InputDate, const char *DateFormat, time_t *lTimestamp){
struct tm tm;
if (NULL == strptime(InputDate, DateFormat, &tm)){
return FALSE;
}
*lTimestamp = mktime(&tm);
return TRUE;
}
Basically, it produces UNIX timestamp out of datetime passed in as a string, with specified format.
char *effPaymentDate = NULL;
char *CohDueDate = NULL;
//...
effPaymentDate = PayRec->RecDate;//char RecDate[8+1];, value 20141005
CohDueDate = PayRec->DueDate;//char DueDate[8+1];, value 20140820
time_t currentDateUNIX;
time_t DueDateUNIX;
if (FALSE == toTimestamp(CohDueDate, "%Y%m%d", &DueDateUNIX) ||
FALSE == toTimestamp(effPaymentDate, "%Y%m%d", ¤tDateUNIX)) {
return NULL;
}
//...
However, it does not seem to work correctly (works OK for effPaymentDate, gives wrong dates for CohDueDate - i.e. year 2543) - any ideas why?