[Solved] QDate Comparision issue



  • Hi friends,

                I am using the expire concept using Qdate. @ QDate date = QDate::currentDate();
    QString currentdate = date.toString("dd-MM-yyyy");
    
    QString expiredate ="07-01-2014";
    
    
    QDate expire1= QDate::fromString(expiredate,"dd-MM-yyyy");
    
    QString s1 = expire1.toString();
    if(s1<currentdate)
    {
        QMessageBox m1;
        m1.setText("Expired");
        m1.exec&#40;&#41;;
    }
    else
    {
        QMessageBox m1;
        m1.setText("Not Expired");
        m1.exec&#40;&#41;;
    }@
    

    This is my code,,in here date comparison is not working,,every time messagebox shows "Not Expired",,,so please help this issue,,

    Thanks


  • Moderators

    You are not comparing QDate objects... you are comparing QString objects. And they, as strings do, compare using alphabetical order comparison. You should use your QDate objects for comparison.



  • Hi sierdzio,,Now it's working,,Thanks


  • Moderators

    I am glad to hear that. I'll mark the thread as solved. Happy coding!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.