The dbquery command is not meant to do any kind of filtering. It simply emits the results of the SQL query. There is no clean approach to filtering results for the selected search timerange in a generic way as a SQL query might emit no, 1 or multiple viable candidates for an event timestamp field.
That being said, you can use SPL (the Splunk search language) to filter the results in the search pipeline. The simplest approach is to use the where command to:
| dbquery mydb "SELECT timestamp_column, other_column1, other_column2 FROM mytable" | where timestamp_column>relative_time(now(),"-7d")
In this example, the results emitted by dbquery would be reduced to those, that match the condition in the where command and will only output results where the value of timestamp_column is within the last 7 days.
A little more sophisticated approach is to additionally use the addinfo command. This adds some meta information about the search to the search results. This allows to actually honor the timerange seleted in the timerange picker.
Here's little search macro that should ease the usage:
[apply_timerange(1)]
args = timefield
definition = addinfo | where $timefield$>=info_min_time AND (info_max_time="+Infinity" OR $timefield$<=info_max_time) | fields - info_min_time info_max_time info_search_time info_sid
iseval = 0
You can add this stanza to macros.conf or add it via Splunk Manager (Advanced Search -> Search Macros). The usage is fairly simple:
| dbquery mydb "SELECT timestamp_column, other_column1, other_column2 FROM mytable" | `apply_timerange(timestamp_column)`
... View more