# Comparing date field in Query does not work for me

**URL:** <https://community.parseplatform.org/t/comparing-date-field-in-query-does-not-work-for-me/765>\
**Category:** JavaScript SDK\
**Created:** [August 30, 2020, 1:51pm UTC](https://community.parseplatform.org/t/comparing-date-field-in-query-does-not-work-for-me/765 "2020-08-30T13:51:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andy](https://community.parseplatform.org/letter_avatar_proxy/v4/letter/a/aeb1de/32.png) [@Andy](https://community.parseplatform.org/u/Andy)\
**Post date:** [August 30, 2020, 1:51pm UTC](https://community.parseplatform.org/t/comparing-date-field-in-query-does-not-work-for-me/765/1 "2020-08-30T13:51:30Z")

</div>

```
query.greaterThan('createdAt', date)

```

where date is a native js Date object. So would be it `greaterThan` or `lessThan` - that part of query doesn’t affect anything like it absent. But because I use aggregation for my request as a solution I apply `match` in pipeline:

```auto
    const pipeline = [
        { match: { createdAt: { $gt: date } } },
        .....
      ];

```

But what can I do in simple query without aggregation?

I read something about intricacy with ISOdate and mongo but it did not clear anything. Tryed instead Date object substitute string (iso timestamp) and number (ms) - does not matter.

---

<div class="post-metadata">

**Author:** ![davimacedo](https://community.parseplatform.org/user_avatar/community.parseplatform.org/davimacedo/32/316_2.png) [@davimacedo](https://community.parseplatform.org/u/davimacedo)\
**Post date:** [August 31, 2020, 5:26am UTC](https://community.parseplatform.org/t/comparing-date-field-in-query-does-not-work-for-me/765/2 "2020-08-31T05:26:06Z")

</div>

`query.greaterThan('createdAt', date)` should work properly. Do you mind to write a failing test case?

---

<div class="post-metadata">

**Author:** ![Andy](https://community.parseplatform.org/letter_avatar_proxy/v4/letter/a/aeb1de/32.png) [@Andy](https://community.parseplatform.org/u/Andy)\
**Post date:** [August 31, 2020, 11:00am UTC](https://community.parseplatform.org/t/comparing-date-field-in-query-does-not-work-for-me/765/3 "2020-08-31T11:00:34Z")

</div>

Thank for the answer. I replaced greaterThan to lessThan with no effect. If you say that it should work fine - my code had some simple/stupid mistake/mistyping.

---

<div class="post-metadata">

**Author:** ![uzaysan](https://community.parseplatform.org/user_avatar/community.parseplatform.org/uzaysan/32/59_2.png) [@uzaysan](https://community.parseplatform.org/u/uzaysan)\
**Post date:** [August 31, 2020, 12:46pm UTC](https://community.parseplatform.org/t/comparing-date-field-in-query-does-not-work-for-me/765/4 "2020-08-31T12:46:30Z")

</div>

I’m using date fields to compare values or ordering objects with no issues. Can you share an example code? Is `date` object defined?

---

<div class="post-metadata">

**Author:** ![Andy](https://community.parseplatform.org/letter_avatar_proxy/v4/letter/a/aeb1de/32.png) [@Andy](https://community.parseplatform.org/u/Andy)\
**Post date:** [August 31, 2020, 1:48pm UTC](https://community.parseplatform.org/t/comparing-date-field-in-query-does-not-work-for-me/765/5 "2020-08-31T13:48:56Z")

</div>

I console.log date object (`today`) of course. Code look like this:

```auto
const now = new Date();
const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());

const statQuery = await query()
  .equalTo('merchant', merchant); // this condition working
  .greaterThan('createdAt', today); // this condition does not effect

const result = await statQuery.aggregate(pipeline)

```

Please take it easy, I understood for the future that date comparing work in simple query (and I workaround it already for that case via comparing inside aggregation), so this problem not so actual.

But I have more interesting question about `group` inside `facet` (will write it soon in new topic).

---

<div class="post-metadata">

**Author:** ![davimacedo](https://community.parseplatform.org/user_avatar/community.parseplatform.org/davimacedo/32/316_2.png) [@davimacedo](https://community.parseplatform.org/u/davimacedo)\
**Post date:** [August 31, 2020, 4:02pm UTC](https://community.parseplatform.org/t/comparing-date-field-in-query-does-not-work-for-me/765/6 "2020-08-31T16:02:19Z")

</div>

I believe you have to either use `greaterThan` or `aggregate`. They won’t work together in the same query.

---

<div class="post-metadata">

**Author:** ![Andy](https://community.parseplatform.org/letter_avatar_proxy/v4/letter/a/aeb1de/32.png) [@Andy](https://community.parseplatform.org/u/Andy)\
**Post date:** [August 31, 2020, 4:25pm UTC](https://community.parseplatform.org/t/comparing-date-field-in-query-does-not-work-for-me/765/7 "2020-08-31T16:25:49Z")

</div>

Thank you, that’s the point. So with aggregation we must use for comparing only something inside `aggregate`, like `match` stage and comparing operators in my first message.

---

<div class="post-metadata">

**Author:** ![davimacedo](https://community.parseplatform.org/user_avatar/community.parseplatform.org/davimacedo/32/316_2.png) [@davimacedo](https://community.parseplatform.org/u/davimacedo)\
**Post date:** [August 31, 2020, 8:47pm UTC](https://community.parseplatform.org/t/comparing-date-field-in-query-does-not-work-for-me/765/8 "2020-08-31T20:47:51Z")

</div>

Yes. I believe they don’t work together. So, when using aggregate, you should use mongodb match operator instead of the sdk functions.
