Nominate our 2022 Qt Champions!

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();
        int yester= yesterday.dayOfWeek();
        std::cout << "Yesterday was the " << yester << " day of the week." << std::endl;

  • Lifetime Qt Champion


    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