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. How to add days,hours and minutes to QDataTime

How to add days,hours and minutes to QDataTime

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 6.3k 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.
  • M Offline
    M Offline
    mark_ua_1999
    wrote on last edited by mark_ua_1999
    #1

    Hi I am trying to change my data adding 2 days and 300 seconds but my code dont work do you have any ideas how to resolve it thanks.
    QString format = "yyyy-MM-dd HH:mm";
    QDateTime a1 = QDateTime::fromString("2017-11-19 12:49", format);//час в дорозі

     a1.addDays(2);
     a1.addSecs(300);
    // a2.addSecs(time[time.size()-i].toInt()+500);
     QString s = a1.toString(format);
    // QString s1 = a2.toString(format);
     ui->textBrowser->append(s);```
    

    //your code here

    JonBJ 1 Reply Last reply
    0
    • M mark_ua_1999

      Hi I am trying to change my data adding 2 days and 300 seconds but my code dont work do you have any ideas how to resolve it thanks.
      QString format = "yyyy-MM-dd HH:mm";
      QDateTime a1 = QDateTime::fromString("2017-11-19 12:49", format);//час в дорозі

       a1.addDays(2);
       a1.addSecs(300);
      // a2.addSecs(time[time.size()-i].toInt()+500);
       QString s = a1.toString(format);
      // QString s1 = a2.toString(format);
       ui->textBrowser->append(s);```
      

      //your code here

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by
      #2

      @mark_ua_1999

       a1.addDays(2);
       a1.addSecs(300);
      

      Look at the documentation. These are functions returning a new QDateTime, they do not change the a1 value.

       a1 = a1.addDays(2);
       a1 = a1.addSecs(300);
      
      M 1 Reply Last reply
      4
      • JonBJ JonB

        @mark_ua_1999

         a1.addDays(2);
         a1.addSecs(300);
        

        Look at the documentation. These are functions returning a new QDateTime, they do not change the a1 value.

         a1 = a1.addDays(2);
         a1 = a1.addSecs(300);
        
        M Offline
        M Offline
        mark_ua_1999
        wrote on last edited by
        #3

        @JNBarchan thanks for your help

        1 Reply Last reply
        0

        • Login

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