jano_alex_es
6th May 2009, 10:29
Hi;
In my application I have a QDateEdit and a database.
I would like to send back from the database the users which date field are before the QDate in the QDateEdit.
I tried the next code, but seems like QDate is not compatible (cannot convert to long,long) with the query:
QDate testDate = ui.my_QDateEdit->date();
QSqlQuery _date((QString("SELECT id FROM users WHERE field_name_in_my_DB='%1' ")
.arg(testDate), *myDatabase->GetDBPtr());
So I tried something that worked... but just when I need the same date, not before (lower), like I'd like:
QString dday = QString::number(ui.my_QDateEdit->date().day());
QString dmonth = QString::number(ui.my_QDateEdit->date().month());
QString dyear = QString::number(ui.my_QDateEdits->date().year());
//In my database the "date" field is "year-month-day"
QString strDate = dyear + "-" + dmonth + "-" + dday;
QSqlQuery _date((QString("SELECT id FROM users WHERE field_name_in_my_DB='%1' ")
.arg(strDate), *myDatabase->GetDBPtr());
I don't know if it helps, but I'm using PostgreSQL.
thanks!
In my application I have a QDateEdit and a database.
I would like to send back from the database the users which date field are before the QDate in the QDateEdit.
I tried the next code, but seems like QDate is not compatible (cannot convert to long,long) with the query:
QDate testDate = ui.my_QDateEdit->date();
QSqlQuery _date((QString("SELECT id FROM users WHERE field_name_in_my_DB='%1' ")
.arg(testDate), *myDatabase->GetDBPtr());
So I tried something that worked... but just when I need the same date, not before (lower), like I'd like:
QString dday = QString::number(ui.my_QDateEdit->date().day());
QString dmonth = QString::number(ui.my_QDateEdit->date().month());
QString dyear = QString::number(ui.my_QDateEdits->date().year());
//In my database the "date" field is "year-month-day"
QString strDate = dyear + "-" + dmonth + "-" + dday;
QSqlQuery _date((QString("SELECT id FROM users WHERE field_name_in_my_DB='%1' ")
.arg(strDate), *myDatabase->GetDBPtr());
I don't know if it helps, but I'm using PostgreSQL.
thanks!