PDA

View Full Version : datetime field



valgaba
7th August 2012, 11:55
I have a database with a datetime field, how I can change the date to the current date time keeping?

thanks

sonulohani
7th August 2012, 12:34
Use QTime (doc.qt.nokia.com/4.7-snapshot/qtime.html).
Extract time from the system and update it in the database.

valgaba
7th August 2012, 18:19
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.


QSqlQuery query(db);
query.prepare("UPDATE HORAS SET DIAHORA = CONCAT(?, time(DIAHORA))");

query.addBindValue(QDate::currentDate());
query.exec();

ChrisW67
8th August 2012, 05:08
How you do this will depend on the database date functions and the exact type of the "date time" column. Which database engine?

valgaba
8th August 2012, 08:45
use QSQLITE


db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(Path + "/Eventos/evento.evt");
db.open();
QSqlQuery query(db);

query.exec("UPDATE HORAS SET HORA = DATE_ADD(HORA, INTERVAL 1 DAY) WHERE rowid > 0"); // error

sonulohani
8th August 2012, 10:43
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.