# Date range query for HistoricTaskInstanceQuery does not work

**URL:** <https://forum.flowable.org/t/date-range-query-for-historictaskinstancequery-does-not-work/12482>\
**Category:** Flowable Engine\
**Created:** [December 1, 2025, 12:00pm UTC](https://forum.flowable.org/t/date-range-query-for-historictaskinstancequery-does-not-work/12482 "2025-12-01T12:00:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kM-Stone](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/km-stone/32/3802_2.png) [@kM-Stone](https://forum.flowable.org/u/kM-Stone)\
**Post date:** [December 1, 2025, 12:00pm UTC](https://forum.flowable.org/t/date-range-query-for-historictaskinstancequery-does-not-work/12482/1 "2025-12-01T12:00:34Z")

</div>

hello there,

I tried using `taskCreatedAfter` and `taskCreatedBefore` to set date range for querying historic task list, and used `taskWithoutDeleteReason` to remove the deleted task. A simple example as:

```auto
    // using Flowable 7.0.1 in java 21
    public List<HistoricTaskInstance> finishedList() {
        HistoricTaskInstanceQuery taskInstanceQuery = historyService.createHistoricTaskInstanceQuery()
                .taskWithoutDeleteReason()
                .orderByHistoricTaskInstanceEndTime().desc();

        // to find results started between period, not ok
        taskInstanceQuery.taskCreatedAfter(DateUtils.parseDate("2025-11-28"));
                         .taskCreatedBefore(DateUtils.parseDate("2025-12-01"));

        // to find results completed between period, not ok
        // taskInstanceQuery.taskCompletedAfter(DateUtils.parseDate("2025-11-28"));
        // .taskCompletedBefore(DateUtils.parseDate("2025-12-01"));

        return taskInstanceQuery.list();
    }

```

However, it didn’t return tasks created (started) between 2025-11-28 and 2025-12-01 as expected; instead, it just returned all tasks (included the deleted tasks, so `taskWithoutDeleteReason` also didn’t work). `taskCompletedAfter` and `taskCompletedBefore`has the same problem.

Then I tried setting one of `taskCompletedAfter, taskCompletedBefore, taskCreatedAfter, or taskCreatedBefore` individually, and they all worked as expected on their own. However, combining them produced results that i cant understand.

But for the similar logic (i.e. find the object started or completed during target time range), I can set date range condition successfully on `historyService.createHistoricProcessInstanceQuery()` and `taskService.createTaskQuery()`, for example:

```auto
// it works as expected
HistoricProcessInstanceQuery historicProcessInstanceQuery = historyService.createHistoricProcessInstanceQuery();
historicProcessInstanceQuery.startedAfter(query.getBeginStartTime());
                            .startedBefore(query.getEndStartTime());

// it works as expected
TaskQuery taskQuery = taskService.createTaskQuery();
taskQuery.taskCreatedAfter(DateUtils.parseDate("2025-11-28"));
         .taskCreatedBefore(DateUtils.parseDate("2025-12-01"));

```

Why is this happening? Did I go wrong?

Thanks in advance. 🥰

---

<div class="post-metadata">

**Author:** ![filiphr](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/filiphr/32/315_2.png) [@filiphr](https://forum.flowable.org/u/filiphr)\
**Post date:** [December 1, 2025, 12:30pm UTC](https://forum.flowable.org/t/date-range-query-for-historictaskinstancequery-does-not-work/12482/2 "2025-12-01T12:30:25Z")

</div>

Hey @kM-Stone,

> [@kM-Stone](#):
>
> However, it didn’t return completed tasks created between 2025-11-28 and 2025-12-01 as expected;

I am a bit confused. You are using `taskCreatedAfter ` and `taskCreatedBefore` and you expect the query to return tasks completed between a certain period. The query options you are using will return you task that have been created in the requested period.

What you need to use is `taskCompletedAfter` and `taskCompletedBefore`, this will return you the tasks that have been completed in a given period.

> [@kM-Stone](#):
>
> But I can set date range condition successfully using `HistoricProcessInstanceQuery ` for process instances, like

I’m not fully following this. What do you mean by it? In that example you are looking for all process instances started after a certain date.

Cheers,  
Filip

---

<div class="post-metadata">

**Author:** ![kM-Stone](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/km-stone/32/3802_2.png) [@kM-Stone](https://forum.flowable.org/u/kM-Stone)\
**Post date:** [December 2, 2025, 2:19am UTC](https://forum.flowable.org/t/date-range-query-for-historictaskinstancequery-does-not-work/12482/3 "2025-12-02T02:19:38Z")

</div>

Thanks for your reply, Filip!  
I’m sorry to my wrong description and I edited my question.

Actually, we want to get the tasks created in a given period, instead of completed tasks. And we also tried `taskCompletedAfter` and `taskCompletedBefore` as you advice, but they also return unexpected results (return all tasks instead of the tasks subject to my condition).  
I tried setting one of `taskCompletedAfter, taskCompletedBefore, taskCreatedAfter, taskCreatedBefore` individually, and they all worked as expected on their own. However, combining them produced results that i cant understand.

> [@filiphr](#):
>
> I’m not fully following this. What do you mean by it? In that example you are looking for all process instances started after a certain date.

sorry, I copied a wrong code and it has been updated. What I’m trying to say here is that similar query logic works in other queryObjects.

---

<div class="post-metadata">

**Author:** ![filiphr](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/filiphr/32/315_2.png) [@filiphr](https://forum.flowable.org/u/filiphr)\
**Post date:** [December 2, 2025, 8:28am UTC](https://forum.flowable.org/t/date-range-query-for-historictaskinstancequery-does-not-work/12482/4 "2025-12-02T08:28:21Z")

</div>

Thanks for clarifying it @kM-Stone.

I had a better look and we had a bug in 7.0.1 there. We were using `or` instead of `and` for `taskCreatedAfter` and etc.

This has been fixed in 7.1.0 and later. Can you try upgrading and see if it works for you? The latest version is 7.2.0.

Cheers,  
Filip

---

<div class="post-metadata">

**Author:** ![kM-Stone](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/km-stone/32/3802_2.png) [@kM-Stone](https://forum.flowable.org/u/kM-Stone)\
**Post date:** [December 5, 2025, 6:53am UTC](https://forum.flowable.org/t/date-range-query-for-historictaskinstancequery-does-not-work/12482/5 "2025-12-05T06:53:12Z")

</div>

Yes, upgrading to 7.2.0 works for me. Thank you !! 👏
