-
Date Comparison
Hi. I have some C/C++ (COM) code I need to use to determine the difference between today's date and a date pulled from a SQL database, and return an error if the difference is greater than 60 days (5184000 seconds). I am using time_t structures to store the DateTime data type that I get from the database. My code is not working, and I'm wondering if there's a better way to store and manipulate the DateTime from the datbase in the COM. Any tips? Here is the code:
time_t currenttime;
currenttime = time(NULL);
time_t oldtime;
//Get previous date/time
m_vConDB.GetField(oldtime, 2);
if ((oldtime == NULL) || (difftime (oldtime,(long)localtime(¤ttime)) > 5184000))
{
return HandleErr(S_FALSE, pError);
}
-
How is it "not working"? What goes wrong exactly?
I guess your code is C++, too? (This is the C board) I can always move the thread to save your re-posting...
-
The code is not working because the value being fetched from the database is a DateTime type, and the time_t type does not seem to get the correct information from the database. So, I think the problem is the type into which I am storing the value from the database, but I don't know what else to use. Yes, you could re-post this in the C++ forum. Thanks.