Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Why is "addDays" not working? (QDate) [SOLVED]



  • Hey,
    I would like to get the day of week of yesterday.
    Therefore I would like to use addDays.
    It does not matter wheter I add or substract days.
    The int yester is always the day of the week from the current day.
    What is wrong?

    Tank you :-)

     QDate yesterday= QDate::currentDate();
        yesterday.addDays(-1);
        int yester= yesterday.dayOfWeek();
        std::cout << "Yesterday was the " << yester << " day of the week." << std::endl;
    

  • Lifetime Qt Champion

    Hi,

    It's working, you're not using it correctly:

    QDate today = QDate::currentDate();
    QDate yesterday = today.addDays(-1);
    

    See here



  • Thank you very much :-)


Log in to reply