Problem accessing to the database with a date[SOLVED]
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:
Code:
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:
Code:
//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!
Re: Problem accessing to the database with a date
Hi, first of all use QSqlQuery::prepare() and QSqlQuery::bindValue() instead of arg(), and then what format has your database entry (timestamp, date or time)?
Re: Problem accessing to the database with a date
... use QDateTime::toString ( const QString & format ) to get the right input format for your database.
Re: Problem accessing to the database with a date
it works fine just including the prepare and binding instead of the quotation marks ^^
thanks again!