Filter month on Qsqltablemodel

Asked

Viewed 70 times

3

How do I filter the month on QSqlTableModel?

I’m doing 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. ThesetFilter is only for WHERE?

  • If you are using SQL Lite?

  • @Fccdias Yes, sqlite

  • By what I researched that’s right, with strftime within the setFilter, it does not issue errors? , Put more information like, the table of this survey, etc ...

  • No mistake in the lastError(); Dates are stored in the format YYYY/MM/DD HH:MM:SS.

  • How to know the SQL that this class generated ?

  • Select * From tabela WHERE strftime('%m', campo_dataCadastro)='04' I think this is the problem select.

  • So the right SQL ta, I myself have tested for example in my case was SELECT * FROM Datas WHERE strftime('%m', Data) = '01', That’s why I find it strange

Show 2 more comments

1 answer

1

Solved, The problem was the date format stored on sqlite. Converts the date to YYYY-MM-DD HH:MM:SS and ran the filter.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.