Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QDateTime without time zone, not working with timer or somenthing?
Qt 6.12 LTS is out! See what's new in the release blog

QDateTime without time zone, not working with timer or somenthing?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 3.9k Views 1 Watching
  • 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hi, i'm new in qt and i need some answers for my question...

    So.. I'm trying to get only date without time zone for my app...

    I found in QT QDateTime but this get time zone too...

    someone know how to do this?

    sorry for my english, i'm not so good..

    the code is:
    @
    QDateTime today = QDateTime::currentDateTime();
    QDateTime tomorrow= today.addDays(1);
    QString sql = "UPDATE agendamento SET data = ? WHERE data < ? AND regra >= 5";
    QSqlQuery query = prepareQuery(sql);

     query.addBindValue(tomorrow);
     query.addBindValue(today.date());@
    

    the result is : 2013-09-03 13:38:57.331
    but I need: 2013-09-03 00:00:00

    Thanks for any help!

    1 Reply Last reply
    0
    • T Offline
      T Offline
      thEClaw
      wrote on last edited by
      #2

      There are two static functions:

      @QDateTime::currentDateTime(); // gives you the curent date and time for the timezone you are in

      QDateTime::currentDateTimeUtc();//ignores the timezone and gives you the current Greenwich Mean Time@

      That second function should do the trick.

      PS: And if I misunderstood you and you actually only want to know the date, use QDate instead:
      @QDate::currentDate();//gives you the current date@

      Alternatively:
      @QDateTime::currentDateTime().date();//same as before@

      I suggest you take a look into the documentation. It's nice in there! ;)

      PPS: Try to choose a more informative title for your thread next time, otherwise people might not read it.

      1 Reply Last reply
      1
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        thEClaw thanks for you support.. i dont know how to explain but thats not work...

        I'm understand whats happens but.. for some reason not works..

        I'm not sure why, but if make a difference I'm using signals and slots..

        check the code:

        @ connect(&_timer, SIGNAL(timeout()), this, SLOT(mostraHora()));
        _timer.setSingleShot(true);
        _timer.setInterval(1000);
        _timer.start();
        }
        void ExecutaHora::mostraHora(){

        /*QProcess myProcess;
         myProcess.execute("date");*/
        
         ConsultaBD consultaBD;
         consultaBD.atualizaBd();
        

        }

        and then the code has modificate to:

        void AgendamentoModel::updateAgendamento(){

         QDateTime today =  QDateTime::currentDateTimeUtc();
        QDateTime tomorrow = QDateTime::currentDateTimeUtc().addDays(1);
         QString sql = "UPDATE agendamento SET data = ? WHERE data < ? AND  regra >= 5";
        QSqlQuery query = prepareQuery(sql);
         query.addBindValue(tomorrow);
         query.addBindValue(today.currentDateTimeUtc());
        
        
         qDebug() << "tomorrow = " << tomorrow;
         qDebug() << "today = " << today;
        
         if(query.exec&#40;&#41;&#41;{
             qDebug(&#41; << "#EXECUTOU QUERY AGENDAMENTO- UPDATEAGENDAMENTO#";
         }else
             qDebug() << "#NAO EXECUTOU QUERY AGENDAMENTO- UPDATEAGENDAMENTO#";
        

        }--@

        thanks for the advice ! and sorry about the first comment without source code rules...

        1 Reply Last reply
        1
        • L Offline
          L Offline
          leon.anavi
          wrote on last edited by
          #4

          [quote author="nicconicco" date="1378140862"]Hi, i'm new in qt and i need some answers for my question...[/quote]

          Please follow the rules of the forum and wrap the source code with @ and write the name of the framework as Qt (pronounced as cute) not QT. More information and examples about "QDateTime":http://qt-project.org/doc/qt-5.0/qtcore/qdatetime.html are available at the official online documentation.

          http://anavi.org/

          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
          • Unsolved