Thread: Date Comparison

  1. #1
    PvtJoker670
    Guest

    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(&currenttime)) > 5184000))
    {
    return HandleErr(S_FALSE, pError);
    }

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    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...
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    PvtJoker670
    Guest
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. Advancing day by day until it matches a second date
    By nhubred in forum C++ Programming
    Replies: 1
    Last Post: 05-30-2009, 08:55 AM
  3. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  4. CDate Class - handle date manipulation simply
    By LuckY in forum C++ Programming
    Replies: 5
    Last Post: 07-16-2003, 08:35 AM