time_t can not represent date before 1970-01-01 and after 2038-02-19?
I am using CDateTimeCtrl to let my users choose their Date of Birth. I
read their DOB from an XML file into a string and then try to convert
it to time_t /CTime to set the CDateTimeCtrl date. SO I wrote a
function to convert string into time_t. (see following)
But most of them born before 1970, my function can not handle those
dates like '1906-01-01 00:00:00'.
does this mean I can not use CDateTimeCtrl for date time pick?
Is there a better way to represent a date before 1970.
-----------------------------------
time_t CUtil::StringToTimestamp(const char* strDate)
{
struct tm timeStruct;
sscanf(LPCSTR(strDate), "%4d-%2d-%2d %2d:%2d:%2d",
&timeStruct.tm_year, &timeStruct.tm_mon,
&timeStruct.tm_mday,
&timeStruct.tm_hour, &timeStruct.tm_min, &timeStruct.tm_sec);
//// adjust the tm structure
timeStruct.tm_mon--;
timeStruct.tm_year -= 1900;
//// do not know if standard or daylight savings time is in effect
timeStruct.tm_isdst = -1;
timeStruct.tm_wday = 0;
timeStruct.tm_yday = 0;
return static_cast<time_t>(mktime(&timeStruct));
}
-------------------
thanks
-rockdale