CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Dec 2007
    Location
    France
    Posts
    329

    Comparing dates of date and time picker control boxes

    I have I have two date and time picker boxes with the same dates in them and when I get the date from them they give different result.

    Code:
    SYSTEMTIME st1 = {0}, st2 = {0};
    
        int r;
        r=SendMessage(hDepart, DTM_GETSYSTEMTIME, 0, (LPARAM)&st1);
        if(r != GDT_VALID) Help("DTM_GETSYSTEMTIME error!");
        r=SendMessage(hReturn, DTM_GETSYSTEMTIME, 0, (LPARAM)&st2);
        if(r != GDT_VALID) Help("DTM_GETSYSTEMTIME error!");
    
        union timeunion {
            FILETIME fileTime;
            ULARGE_INTEGER ul;
        } ;
    
        timeunion ft1;
        timeunion ft2;
    
        SystemTimeToFileTime(&st1, &ft1.fileTime);
        SystemTimeToFileTime(&st2, &ft2.fileTime);
    
        cout << "time " <<  ft1.ul.QuadPart << endl;
        cout << "time " <<  ft2.ul.QuadPart << endl;
    Why don't they give the same result? I would like to compare them.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: Comparing dates of date and time picker control boxes

    Quote Originally Posted by MasterDucky View Post
    I have I have two date and time picker boxes with the same dates in them and when I get the date from them they give different result.
    ...
    Why don't they give the same result? I would like to compare them.
    I'm confused.
    Is the result different or the same?
    And what is "the result" and what is it supposed to be?
    Victor Nijegorodov

  3. #3
    Join Date
    Dec 2007
    Location
    France
    Posts
    329

    Re: Comparing dates of date and time picker control boxes

    Hi Victor,

    I should get the same result because they have the same dates in it.
    But I get these two different values:

    time 129968818494020000
    time 129968818494290000

    Thanks for your help!

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: Comparing dates of date and time picker control boxes

    And what values do they have?
    Victor Nijegorodov

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: Comparing dates of date and time picker control boxes

    Well, the difference between these two times is 27 ms.
    So how did you detect that the times in both datetime controls are equal?
    Victor Nijegorodov

  6. #6
    Join Date
    Dec 2007
    Location
    France
    Posts
    329

    Re: Comparing dates of date and time picker control boxes

    Today's date in this format: 08 / 11 / 2012 thursday

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: Comparing dates of date and time picker control boxes

    Quote Originally Posted by MasterDucky View Post
    Today's date in this format: 08 / 11 / 2012 thursday
    How did you set it to both controls? And when?
    Victor Nijegorodov

  8. #8
    Join Date
    Dec 2007
    Location
    France
    Posts
    329

    Re: Comparing dates of date and time picker control boxes

    I think it gets set automatically because I only send a DTM_SETFORMAT message when they are created. This is the format I use
    LPSTR lpstrDate = "dd / MM / yyy dddd";

  9. #9
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: Comparing dates of date and time picker control boxes

    Then why do you think they dad to be equal?
    Sur they are set not simultaneously but one after another while the creating the controls!

    Just try to set the same datetime values to them using DTM_SETSYSTEMTIME message and see what will happen!
    Victor Nijegorodov

  10. #10
    Join Date
    Dec 2007
    Location
    France
    Posts
    329

    Re: Comparing dates of date and time picker control boxes

    Yes if I set them myself they are the same. :-)

    That makes sense, thank you Victor!

  11. #11
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: Comparing dates of date and time picker control boxes

    You are welcome!
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured