2

I try to query with an expression I found in older posts:

 week(age(now(),end_time)) <= 1

Where end_time is of QDateTime.

I am getting back:

An error occurred when executing the query.
The data provider said:
ERROR:  function week(interval) does not exist
                                                 ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

I tried with day instead of week and got a similar result.

Could you, please, help we to find out where I have a mistake.

3
  • What version of QGIS are you using? How is end_time formatted? If you just put "end_time" in the expression box then does the preview look like <date: yyyy-mm-dd>? Nov 3, 2022 at 13:36
  • I use 3.16.16. Where I can see preview?
    – Belurd
    Nov 3, 2022 at 13:42
  • Field format is yyyy-MM-dd HH:mm:ss
    – Belurd
    Nov 3, 2022 at 13:43

1 Answer 1

1

now() is a fickle companion. The moment you query it, it already is gone. Nail it down firmly using to_date() and at least until midnight it wont change.

Or, in a less poetic manner of speaking: You need to hand two datetimes of the same format & length to age(). Force now() into the same format as your end_time and you'll be fine.

1
  • I don't need it as stable. I am interested in building a layer that shows the last week of events in days. That is why the exact moment would not be a big deal.
    – Belurd
    Nov 3, 2022 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.