# Adding a filter with a between for 2 dates

**URL:** <https://community.hubspot.com/t/adding-a-filter-with-a-between-for-2-dates/79903>\
**Category:** APIs & Integrations\
**Tags:** crm, contacts\
**Created:** [April 24, 2023, 8:32am UTC](https://community.hubspot.com/t/adding-a-filter-with-a-between-for-2-dates/79903 "2023-04-24T08:32:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![RKINZELIN](https://avatars.discourse-cdn.com/v4/letter/r/b77776/32.png) [@RKINZELIN](https://community.hubspot.com/u/RKINZELIN)\
**Post date:** [April 24, 2023, 8:32am UTC](https://community.hubspot.com/t/adding-a-filter-with-a-between-for-2-dates/79903/1 "2023-04-24T08:32:26Z")

</div>

Hello everyone, I would like to know how to add a “between” filter to take a value between 2 dates.

Here is the code I did:

`if (inputBecameStart !== "undefined" && inputBecameEnd !== "undefined" && statut !== "undefined") { let dateEnd = inputBecameEnd; let dateStart = inputBecameStart; let filter = { propertyName: "hs_lifecyclestage_"+statut+"_date", operator: "BETWEEN", value: new Date(dateStart).toISOString(), highValue: new Date(dateEnd).toISOString() } PublicObjectSearchRequest.filterGroups[0].filters[i] = filter; i++;}`

but I have this error: ‘Invalid input JSON on line 1, column 135: operator BETWEEN requires a highValue’

which I do not understand because for me I have already put highValue thank you for trying to help me understand this error 🙂

---

<div class="post-metadata">

**Author:** ![ChrisoKlepke](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/chrisoklepke/32/11213_2.png) [@ChrisoKlepke](https://community.hubspot.com/u/ChrisoKlepke)\
**Post date:** [April 24, 2023, 12:54pm UTC](https://community.hubspot.com/t/adding-a-filter-with-a-between-for-2-dates/79903/2 "2023-04-24T12:54:06Z")

</div>

Hey @RKINZELIN ,

Since you’re using the toISOString method, I assume your dates would result in something like this:

“2023-04-24T12:34:56.789Z”

However, HubSpot expects Unix timestamps in milliseconds here. So something like this:  
1682340819000

If you found this post helpful, consider helping others in the community to find answers faster by marking this as a solution. I’d really appreciate it.

Cheers,

Chriso

---

<div class="post-metadata">

**Author:** ![RKINZELIN](https://avatars.discourse-cdn.com/v4/letter/r/b77776/32.png) [@RKINZELIN](https://community.hubspot.com/u/RKINZELIN)\
**Post date:** [April 25, 2023, 9:18pm UTC](https://community.hubspot.com/t/adding-a-filter-with-a-between-for-2-dates/79903/3 "2023-04-25T21:18:10Z")

</div>

hello Chriso-mwx,

yes I tried the same but without success with the same error while I put the high value 😞

---

<div class="post-metadata">

**Author:** ![RKINZELIN](https://avatars.discourse-cdn.com/v4/letter/r/b77776/32.png) [@RKINZELIN](https://community.hubspot.com/u/RKINZELIN)\
**Post date:** [April 25, 2023, 9:43pm UTC](https://community.hubspot.com/t/adding-a-filter-with-a-between-for-2-dates/79903/4 "2023-04-25T21:43:12Z")

</div>

`let filter1 = { propertyName: "hs_lifecyclestage_"+statut+"_date", operator: "BETWEEN", value: new Date(dateStart).getTime(), highValue: new Date(dateEnd).getTime()}PublicObjectSearchRequest.filterGroups[filterCount].filters[i] = filter1;`

---

<div class="post-metadata">

**Author:** ![ChrisoKlepke](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/chrisoklepke/32/11213_2.png) [@ChrisoKlepke](https://community.hubspot.com/u/ChrisoKlepke)\
**Post date:** [April 26, 2023, 8:28am UTC](https://community.hubspot.com/t/adding-a-filter-with-a-between-for-2-dates/79903/5 "2023-04-26T08:28:32Z")

</div>

Hey @RKINZELIN ,

can you give a bit more context? It’s best for the community to get the bigger picture, so they have the best chance of helping you. Like, for example, what would be an example of a value in the inputBecameStart variable? Where is the PublicObjectSearchRequest being set? What else have you tried? Did you pass the UNIX timestamps as strings instead of an integer before?

I can’t really test this case, unfortunately, as I can’t tell what exactly is going.

Best,

Chriso

---

<div class="post-metadata">

**Author:** ![RKINZELIN](https://avatars.discourse-cdn.com/v4/letter/r/b77776/32.png) [@RKINZELIN](https://community.hubspot.com/u/RKINZELIN)\
**Post date:** [April 26, 2023, 8:48am UTC](https://community.hubspot.com/t/adding-a-filter-with-a-between-for-2-dates/79903/6 "2023-04-26T08:48:30Z")

</div>

Hey [Chriso-mwx](https://community.hubspot.com/t5/user/viewprofilepage/user-id/241684),

I make a program that allows to take some contacts according to filter and therefore at the beginning of my main function I initialize my

PublicObjectSearchRequest like this:

`let PublicObjectSearchRequest = { filterGroups : [{filters:[]}], sorts: [""], query: "", properties: ['firstname', 'lastname', 'email', 'phone', 'page_views'], limit: 0, after: 0 };`

then I add all the filters except between which are specific

`let i = 0;let filterCount = 0; if (filtres.length !== 0) { filtres.forEach(element => { let filtre = { propertyName: element.propertyName, operator: element.operator, value: element.value } PublicObjectSearchRequest.filterGroups[filterCount].filters.push(filtre); i++; if(i===3){ filterCount++; i=0; PublicObjectSearchRequest.filterGroups[filterCount] = {filters:[]}; } }); }`

Finally, I create the filter with the between as I sent you just before which generates the error that I do not understand since it does not recognize at all the “highValue” that I put. For the value I tried all (string, float, int) sde same for the format but the error clearly shows that it does not find the highValue at all.

---

<div class="post-metadata">

**Author:** ![RKINZELIN](https://avatars.discourse-cdn.com/v4/letter/r/b77776/32.png) [@RKINZELIN](https://community.hubspot.com/u/RKINZELIN)\
**Post date:** [April 27, 2023, 1:38pm UTC](https://community.hubspot.com/t/adding-a-filter-with-a-between-for-2-dates/79903/7 "2023-04-27T13:38:37Z")

</div>

Hey,

I’m sorry to tell you this but for me your filter with “BETWEEN” as operator does not work. 😞
