Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QDate matching not working Qt5 always getting false
QtWS25 Last Chance

QDate matching not working Qt5 always getting false

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 407 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rkt1989
    wrote on last edited by
    #1

    I am trying to match which date is greater than another

    I am getting system date using following code

    QDate systemDate = QDate::currentDate();
            QString date1 = systemDate.toString("yyyy/MM/dd");
            QDate systemDate1;
            systemDate1.fromString(date1,"yyyy/MM/dd");
    

    and system event log date

    QString xml = getStringFromEvent(publisherMetaData, nextEvents[i], EvtFormatMessageXml);
                    //winEventList.append(eventInfo);
                    QDomDocument dom;
                    dom.setContent(xml);
                    QString dateTime = dom.elementsByTagName("TimeCreated").at(0).toElement().attribute("SystemTime");
                    QString date = dateTime.section("T", 0, 0);
                    QDate logDate;
                    logDate.fromString(date,"yyyy/MM/dd");
    

    but when i try to compare using following code i always get false even when system date < log date

    if(logDate > systemDate1){
                        clockChanged = true;
                        break;
                    }
    

    can anyone suggest some modification thank you.

    KroMignonK 1 Reply Last reply
    0
    • R rkt1989

      I am trying to match which date is greater than another

      I am getting system date using following code

      QDate systemDate = QDate::currentDate();
              QString date1 = systemDate.toString("yyyy/MM/dd");
              QDate systemDate1;
              systemDate1.fromString(date1,"yyyy/MM/dd");
      

      and system event log date

      QString xml = getStringFromEvent(publisherMetaData, nextEvents[i], EvtFormatMessageXml);
                      //winEventList.append(eventInfo);
                      QDomDocument dom;
                      dom.setContent(xml);
                      QString dateTime = dom.elementsByTagName("TimeCreated").at(0).toElement().attribute("SystemTime");
                      QString date = dateTime.section("T", 0, 0);
                      QDate logDate;
                      logDate.fromString(date,"yyyy/MM/dd");
      

      but when i try to compare using following code i always get false even when system date < log date

      if(logDate > systemDate1){
                          clockChanged = true;
                          break;
                      }
      

      can anyone suggest some modification thank you.

      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by KroMignon
      #2

      @rkt1989 said in QDate matching not working Qt5 always getting false:

      logDate.fromString(date,"yyyy/MM/dd");

      Are you sure date contains a valid date string?
      Check if logdate.isValid() returns true.

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      R 1 Reply Last reply
      0
      • R Offline
        R Offline
        rkt1989
        wrote on last edited by
        #3
        qDebug("Hello "+date.toLatin1()+"");
        

        gives me following output
        Hello 2020/09/10
        Hello 2020/09/10
        Hello 2020/09/09

        qDebug("Hello "+date1.toLatin1()+"");
        

        gives me following output

        Hello 2020/09/10

        1 Reply Last reply
        0
        • KroMignonK KroMignon

          @rkt1989 said in QDate matching not working Qt5 always getting false:

          logDate.fromString(date,"yyyy/MM/dd");

          Are you sure date contains a valid date string?
          Check if logdate.isValid() returns true.

          R Offline
          R Offline
          rkt1989
          wrote on last edited by
          #4

          @KroMignon

          logdate.isValid()
          

          is returning false what should i do

          1 Reply Last reply
          0
          • Christian EhrlicherC Online
            Christian EhrlicherC Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @rkt1989 said in QDate matching not working Qt5 always getting false:

            what should i do

            think about why it's the case... Did you check the string?

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            R 1 Reply Last reply
            1
            • Christian EhrlicherC Christian Ehrlicher

              @rkt1989 said in QDate matching not working Qt5 always getting false:

              what should i do

              think about why it's the case... Did you check the string?

              R Offline
              R Offline
              rkt1989
              wrote on last edited by
              #6

              @Christian-Ehrlicher ok i fixed that with

              QDate logDate = QDate::fromString(date,"yyyy-MM-dd");
              
              Christian EhrlicherC 1 Reply Last reply
              0
              • R rkt1989

                @Christian-Ehrlicher ok i fixed that with

                QDate logDate = QDate::fromString(date,"yyyy-MM-dd");
                
                Christian EhrlicherC Online
                Christian EhrlicherC Online
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @rkt1989 Then please mark this topic as solved.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                1

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved