[Solved] Comparing two dates

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:

Working correctly:

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?

1 Like

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

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

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.

3 Likes

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.

3 Likes

A small update to make the problem more clear.

1 Like

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.

2 Likes

@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.

2 Likes

@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:

3 Likes