# \[Solved\] Comparing two dates

**URL:** <https://community.thunkable.com/t/solved-comparing-two-dates/1194046>\
**Category:** Questions about Thunkable X\
**Tags:** solved\
**Created:** [March 29, 2021, 3:24pm UTC](https://community.thunkable.com/t/solved-comparing-two-dates/1194046 "2021-03-29T15:24:19Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![andreyandrievich](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/andreyandrievich/32/94386_2.png) [@andreyandrievich](https://community.thunkable.com/u/andreyandrievich)\
**Post date:** [March 29, 2021, 3:24pm UTC](https://community.thunkable.com/t/solved-comparing-two-dates/1194046/1 "2021-03-29T15:24:19Z")

</div>

The logic element “ **First element is Greater** ” is not work, but the logic element “First element is Smaller” is work correctly.

I use it with Airtable (column with dates).

**I can’t find the rows with dates greater then dateX** , but can find the rows with dates less then dateX.

**Not working:**

 ![greater](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/c/1/c156fd7285254394353e4dd8b75f4bfa1590f939.png)

**Working correctly:**

 ![less](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/0/a/0af587444ec038185ca18189e8116c80900b59f6.png)

---

<div class="post-metadata">

**Author:** ![domhnallohanlon](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/domhnallohanlon/32/29554_2.png) [@domhnallohanlon](https://community.thunkable.com/u/domhnallohanlon)\
**Post date:** [March 29, 2021, 4:00pm UTC](https://community.thunkable.com/t/solved-comparing-two-dates/1194046/2 "2021-03-29T16:00:24Z")

</div>

but you’re also using two different variables here @andreyandrievich - the one that doesn’t work is subtracting `P_AgeMax` whereas the one that doesn’t work is using `P_AgeMin`

Is it possible that this difference is causing the issue?

---

<div class="post-metadata">

**Author:** ![andreyandrievich](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/andreyandrievich/32/94386_2.png) [@andreyandrievich](https://community.thunkable.com/u/andreyandrievich)\
**Post date:** [March 29, 2021, 4:14pm UTC](https://community.thunkable.com/t/solved-comparing-two-dates/1194046/3 "2021-03-29T16:14:53Z")

</div>

No, the variable does not cause a problem (I checked in additionally)

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [March 29, 2021, 4:35pm UTC](https://community.thunkable.com/t/solved-comparing-two-dates/1194046/4 "2021-03-29T16:35:39Z")

</div>

You are comparing two text strings so the \< or \> than block is going to treat them as words and sort them alphabetically.

I tested this and 2/1/22 \< 3/29/21 evaluates as true because the first character on the left “2” comes before the first character on the right “3”.

These blocks evaluate to true and the result when previewed is “\<”:

![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/b/a/bad51b2a547b41825ab9490e085be59a90bf1e46.png)

I think you either need to compare dates to dates (not strings to strings) or you need to parse the date string you’re using and check the day, then the month, and then the year.

Or… use an API to determine which date comes first.

---

<div class="post-metadata">

**Author:** ![jared](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jared/32/138473_2.png) [@jared](https://community.thunkable.com/u/jared)\
**Post date:** [March 29, 2021, 5:34pm UTC](https://community.thunkable.com/t/solved-comparing-two-dates/1194046/5 "2021-03-29T17:34:34Z")

</div>

The most accurate way to compare two dates would be to convert them into Unix/epoch format and compare those.

Unfortunately at this time, the moment/luxon(?) Library blocks available in thunkable are super limited making working with dates difficult.

One way to compare would be to use something like

Yearmonthday values with no punctuation like slash or hyphen

For example

20210323 or March 23 2021

Then you can compare numbers which is easier

`20210323 > 20210321` evaluates if March 23 is bigger than March 21 and since date is an expression of time passed since the beginning, this makes sense and works.

---

<div class="post-metadata">

**Author:** ![andreyandrievich](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/andreyandrievich/32/94386_2.png) [@andreyandrievich](https://community.thunkable.com/u/andreyandrievich)\
**Post date:** [March 29, 2021, 7:25pm UTC](https://community.thunkable.com/t/solved-comparing-two-dates/1194046/6 "2021-03-29T19:25:59Z")

</div>

A small update to make the problem more clear.

 ![123123123](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/4/7/47db320d4a924b5077139e59ed800707c6c65ef5.png)

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [March 29, 2021, 7:36pm UTC](https://community.thunkable.com/t/solved-comparing-two-dates/1194046/7 "2021-03-29T19:36:44Z")

</div>

You need to compare the first character of the value in the property “Birthday” and compare it with the first character of “day of the month”

For today, “29” then all dates of “Birthday” will be **less than** unless the birthday is “30” of the month. Assuming your “Birthday” variable has leading zeros.

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [March 29, 2021, 9:14pm UTC](https://community.thunkable.com/t/solved-comparing-two-dates/1194046/8 "2021-03-29T21:14:39Z")

</div>

@andreyandrievich If you haven’t read my post yet, take a look. I explain why \< and \> aren’t both working properly.

@jared good suggestion about re-formatting the date in order to check the year first.

---

<div class="post-metadata">

**Author:** ![andreyandrievich](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/andreyandrievich/32/94386_2.png) [@andreyandrievich](https://community.thunkable.com/u/andreyandrievich)\
**Post date:** [March 30, 2021, 9:29am UTC](https://community.thunkable.com/t/solved-comparing-two-dates/1194046/9 "2021-03-30T09:29:37Z")

</div>

@tatiang, @muneer, @jared,  
Thank you very much, your answers gave me the right decision.

**I just changed the date format to ISO and it helped:**

 ![Снимок экрана 2021-03-30 в 12.26.15](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/f/1/f1b495f192a706f95b8f5899d3754837cd95cfca.png)

---

<div class="post-metadata">

**Author:** ![ioannis](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/ioannis/32/146956_2.png) [@ioannis](https://community.thunkable.com/u/ioannis)\
**Post date:** [November 8, 2024, 1:25pm UTC](https://community.thunkable.com/t/solved-comparing-two-dates/1194046/10 "2024-11-08T13:25:39Z")

</div>


