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. Why is "addDays" not working? (QDate) [SOLVED]
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved General and Desktop
qdate
3 Posts 2 Posters 1.9k 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
    RolBri
    wrote on 21 Jul 2015, 07:52 last edited by RolBri
    #1

    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;
    
    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 21 Jul 2015, 07:59 last edited by
      #2

      Hi,

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

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

      See here

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • R Offline
        R Offline
        RolBri
        wrote on 21 Jul 2015, 08:03 last edited by
        #3

        Thank you very much :-)

        1 Reply Last reply
        0

        2/3

        21 Jul 2015, 07:59

        • Login

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