# Querying datetime fields

**URL:** <https://forum.builder.io/t/querying-datetime-fields/143>\
**Category:** Technical Questions\
**Created:** [July 17, 2020, 9:10pm UTC](https://forum.builder.io/t/querying-datetime-fields/143 "2020-07-17T21:10:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![aubergine](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.builder.io/aubergine/32/123_2.png) [@aubergine](https://forum.builder.io/u/aubergine)\
**Post date:** [July 17, 2020, 9:10pm UTC](https://forum.builder.io/t/querying-datetime-fields/143/1 "2020-07-17T21:10:01Z")

</div>

I’m having problems filtering dates. Maybe this is because of the format? Or maybe my content needs some reindex on Builder side?

I’m sending eg.:

`query.data.dateFrom.$gte: "Fri Jul 17 2020 02:00:00 GMT 0200 (Central European Summer Time)"`

and I’m getting results like:

`dateFrom: "Wed Jul 15 2020 00:00:00 GMT+0200 (Central European Summer Time)"`.

(_Wed Jul 15 2020_… is the actual field value coming from REST API)

Looks like the backend compares strings, not dates 🤔

Question is: how to query datetime fields properly?

---

<div class="post-metadata">

**Author:** ![kara](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.builder.io/kara/32/80_2.png) [@kara](https://forum.builder.io/u/kara)\
**Post date:** [July 17, 2020, 10:37pm UTC](https://forum.builder.io/t/querying-datetime-fields/143/2 "2020-07-17T22:37:10Z")

</div>

Hi, thanks for reaching out! It seems like you might be trying to target specific content by using $gte. Would you mind providing a little more context around what you’re trying to achieve? Thanks!

---

<div class="post-metadata">

**Author:** ![aubergine](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.builder.io/aubergine/32/123_2.png) [@aubergine](https://forum.builder.io/u/aubergine)\
**Post date:** [July 17, 2020, 10:53pm UTC](https://forum.builder.io/t/querying-datetime-fields/143/3 "2020-07-17T22:53:22Z")

</div>

Sure!  
For simplicity: I have a model eg. `myEntry`, which has a field `date` of type `Date`.  
Then I’m creating few `myEntry` entities with different dates. (API returns values formatted like this: `Wed Jul 15 2020 00:00:00 GMT+0200 (Central European Summer Time)`.)

Then I’m trying to filter entries by my `date` field: before and after specific date.

For entries with date set BEFORE specific date (or equal to) I was trying:  
`query.data.date.$lte: [some date toString() or toISOString()]`,

and for the opposite  
`query.data.date.$gte: [some date toString() or toISOString()]`.

With no luck…

---

<div class="post-metadata">

**Author:** ![kara](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.builder.io/kara/32/80_2.png) [@kara](https://forum.builder.io/u/kara)\
**Post date:** [July 20, 2020, 4:50pm UTC](https://forum.builder.io/t/querying-datetime-fields/143/4 "2020-07-20T16:50:30Z")

</div>

Thanks for the details! We’re working on getting an update released soon so that it will be saved as a timestamp (number). That way you can do something like this:

`query.data.dateInput.$gte: new Date(...).getTime()`

[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Date/getTime](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime)

I’ll follow-up to let you know when it’s been released!

---

<div class="post-metadata">

**Author:** ![kara](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.builder.io/kara/32/80_2.png) [@kara](https://forum.builder.io/u/kara)\
**Post date:** [July 29, 2020, 10:08pm UTC](https://forum.builder.io/t/querying-datetime-fields/143/5 "2020-07-29T22:08:28Z")

</div>

Hi @aubergine! I wanted to let you know that this functionality has been released and you can use the timestamp field type for your query. Please don’t hesitate to reach out if you have additional questions!

---

<div class="post-metadata">

**Author:** ![aubergine](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.builder.io/aubergine/32/123_2.png) [@aubergine](https://forum.builder.io/u/aubergine)\
**Post date:** [July 29, 2020, 10:21pm UTC](https://forum.builder.io/t/querying-datetime-fields/143/6 "2020-07-29T22:21:03Z")

</div>

👌 🙂

---

<div class="post-metadata">

**Author:** ![marinelbg](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.builder.io/marinelbg/32/2742_2.png) [@marinelbg](https://forum.builder.io/u/marinelbg)\
**Post date:** [October 31, 2023, 3:37pm UTC](https://forum.builder.io/t/querying-datetime-fields/143/7 "2023-10-31T15:37:14Z")

</div>

Hi,

I’m having the same issue but for the field `publishedAt` which seems to be saved as a date and not as a timestamp.  
Any way to query content depending on the published date ?

Thanks
