Results 1 to 6 of 6

Thread: datetime field

  1. #1
    Join Date
    Mar 2010
    Location
    spain
    Posts
    25
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default datetime field

    I have a database with a datetime field, how I can change the date to the current date time keeping?

    thanks

  2. #2
    Join Date
    May 2012
    Location
    Bangalore, India
    Posts
    271
    Thanks
    29
    Thanked 50 Times in 47 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: datetime field

    Use QTime.
    Extract time from the system and update it in the database.
    Heavy Metal Rules. For those about to rock, we salute you.
    HIT THANKS IF I HELPED.

  3. #3
    Join Date
    Mar 2010
    Location
    spain
    Posts
    25
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: datetime field

    I have a table with a datetime field you can change all values ​​in the field of time keeping and changed the part of date.
    The field looks like this:
    2012-08-07T11: 38:00
    You can change the 08/07/2012 holding T11: 38:00 intact.

    Qt Code:
    1. QSqlQuery query(db);
    2. query.prepare("UPDATE HORAS SET DIAHORA = CONCAT(?, time(DIAHORA))");
    3.  
    4. query.addBindValue(QDate::currentDate());
    5. query.exec();
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: datetime field

    How you do this will depend on the database date functions and the exact type of the "date time" column. Which database engine?

  5. #5
    Join Date
    Mar 2010
    Location
    spain
    Posts
    25
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: datetime field

    use QSQLITE

    Qt Code:
    1. db = QSqlDatabase::addDatabase("QSQLITE");
    2. db.setDatabaseName(Path + "/Eventos/evento.evt");
    3. db.open();
    4. QSqlQuery query(db);
    5.  
    6. query.exec("UPDATE HORAS SET HORA = DATE_ADD(HORA, INTERVAL 1 DAY) WHERE rowid > 0"); // error
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    May 2012
    Location
    Bangalore, India
    Posts
    271
    Thanks
    29
    Thanked 50 Times in 47 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: datetime field

    hey you're writing the wrong SQL Statements. Set all the value of Date in the variables and update it here. How SQLite will know that you're using the date_add function.
    Heavy Metal Rules. For those about to rock, we salute you.
    HIT THANKS IF I HELPED.

Similar Threads

  1. Difference between two DateTime object
    By merry in forum Qt Programming
    Replies: 2
    Last Post: 11th February 2010, 04:15
  2. SQLite DATETIME fieldtype
    By phildu44 in forum Qt Programming
    Replies: 5
    Last Post: 30th December 2009, 07:38
  3. bindValue string to datetime db field
    By pmlody in forum Qt Programming
    Replies: 0
    Last Post: 19th September 2009, 09:48
  4. How to get seconds diferences between two datetime
    By gustavedgardo in forum Newbie
    Replies: 1
    Last Post: 4th March 2009, 22:05
  5. How to change system DateTime?
    By FreePascal in forum Qt Programming
    Replies: 8
    Last Post: 5th April 2008, 14:50

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.