c++ – Filter month in QSqlTableModel

Question:

How do I filter the month in QSqlTableModel ?

I'm doing it like this:

model = new QSqlTableModel(this);
model->setTable("tabela"); // db sqlite
model->setFilter("strftime('%m', campo_dataCadastro)='04'");//db YYYY/MM/DD HH:MM:SS
model->select();

But without success. Is setFilter only for WHERE ?

Answer:

Fixed, The problem was the date format stored in sqlite . Convert date to YYYY-MM-DD HH:MM:SS and the filter worked.

Scroll to Top