# More or less than on dates

**URL:** <https://community.hubspot.com/t/more-or-less-than-on-dates/25535>\
**Category:** CMS Development\
**Tags:** hubdb\
**Created:** [September 16, 2020, 3:28pm UTC](https://community.hubspot.com/t/more-or-less-than-on-dates/25535 "2020-09-16T15:28:49Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ben-duchy](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/ben-duchy/32/84083_2.png) [@ben-duchy](https://community.hubspot.com/u/ben-duchy)\
**Post date:** [September 16, 2020, 3:28pm UTC](https://community.hubspot.com/t/more-or-less-than-on-dates/25535/1 "2020-09-16T15:28:49Z")

</div>

Does anyone know if it’s possible to run an if statement based on a date in hubdb?

I have a set of dates in a column which pulls through fine, but when trying to amend it with an if statement, it doesn’t work!  
I am trying to display 1 of 2 items depending on the date. e.g. if it’s before 1 March 2021 then show A content else show B content  
**{% elif row[“anticipated-build-completion”] | datetimeformat(‘%e %B %Y’) \> ‘1 March 2021’ %}**  
Show A content  
**{% else %}**  
Show B content  
**{% endif %}**  
What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![stefen](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/stefen/32/29274_2.png) [@stefen](https://community.hubspot.com/u/stefen)\
**Post date:** [September 16, 2020, 4:06pm UTC](https://community.hubspot.com/t/more-or-less-than-on-dates/25535/2 "2020-09-16T16:06:05Z")

</div>

@ben-duchy the problem is because you are formatting it, then trying to use math/logic on a formatted date. Instead, you should try using the [unixtimestamp](https://developers.hubspot.com/docs/cms/hubl/functions#unixtimestamp) equivalant for the date. This way you are just comparing two numbers with each other so the computer can understand what you’re doing… so something like this:

```lia-code-sample
{% if unixtimestamp(row.datetimeobject) < 1614556800 %}
I'm a date before March 1st 2021!
{% endif %}

```

---

<div class="post-metadata">

**Author:** ![ben-duchy](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/ben-duchy/32/84083_2.png) [@ben-duchy](https://community.hubspot.com/u/ben-duchy)\
**Post date:** [September 18, 2020, 8:30am UTC](https://community.hubspot.com/t/more-or-less-than-on-dates/25535/3 "2020-09-18T08:30:34Z")

</div>

Hi @stefen, great idea, I wasn’t even aware of this method.

Unfortunately I can’t get it to work correctly as its pulling in all rows to show ‘A content’ or ‘B content’ depending on the less / more arrow used. It’s not filtering them!  
Do I need to do anything different in HubDB?

---

<div class="post-metadata">

**Author:** ![Kevin-C](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/kevin-c/32/34570_2.png) [@Kevin-C](https://community.hubspot.com/u/Kevin-C)\
**Post date:** [September 16, 2020, 5:42pm UTC](https://community.hubspot.com/t/more-or-less-than-on-dates/25535/4 "2020-09-16T17:42:43Z")

</div>

Hey @ben-duchy

Looks like you open you if statement with an else if rather than an if. try this:

```lia-code-sample
{% if row["anticipated-build-completion"] | datetimeformat('%e %B %Y') > '1 March 2021' %}
Show A content
{% else %}
Show B content
{% endif %}

```

---

<div class="post-metadata">

**Author:** ![ben-duchy](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/ben-duchy/32/84083_2.png) [@ben-duchy](https://community.hubspot.com/u/ben-duchy)\
**Post date:** [September 18, 2020, 8:11am UTC](https://community.hubspot.com/t/more-or-less-than-on-dates/25535/5 "2020-09-18T08:11:31Z")

</div>

Hi @Kevin-C, thanks for your reply. It’s part of a wider condition - I forgot to mention that.

---

<div class="post-metadata">

**Author:** ![Kevin-C](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/kevin-c/32/34570_2.png) [@Kevin-C](https://community.hubspot.com/u/Kevin-C)\
**Post date:** [September 18, 2020, 6:38pm UTC](https://community.hubspot.com/t/more-or-less-than-on-dates/25535/6 "2020-09-18T18:38:52Z")

</div>

Hey @ben-duchy

Ahh gotcha.

I wonder if the mutating/formatting of the data is getting in the way.

As a best practice we try to avoid mutating data until the last possible time (usually displaying it). We do this because mutating data back and forth can make it hard to track and understand the state of the data. Also when comparing a dynamic value with a static value we try to match the static value’s format to that of the dynamic.

To test if this might be the case try printing the variable and comparing manually:

`{{ row["anticipated-build-completion"] }}`

Basically take a look at that output and then try to modify the static date format you’re checking against.

This should make the bug easier to assess.

**EDIT**

**Im working through a test now will follow up soon**

---

<div class="post-metadata">

**Author:** ![Kevin-C](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/kevin-c/32/34570_2.png) [@Kevin-C](https://community.hubspot.com/u/Kevin-C)\
**Post date:** [September 18, 2020, 6:58pm UTC](https://community.hubspot.com/t/more-or-less-than-on-dates/25535/7 "2020-09-18T18:58:35Z")

</div>

Hey again @ben-duchy

Try this:

```lia-code-sample
{% set staticDate = "2021-03-01T00:00:00+0000"|strtotime("yyyy-MM-dd'T'HH:mm:ssZ") %}{# the date you're checking against #}
{% set dynmDate = row["anticipated-build-completion"] %} {# your dynamic date #}

{% if dynmDate|between_times(staticDate, 'days') >= 1 %} {# Check using between times #}

 {# if the date is before teh staticDate #}

 {% elif %}

 {# if the date is after teh staticDate #}

{% endif %}

```

---

<div class="post-metadata">

**Author:** ![ben-duchy](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/ben-duchy/32/84083_2.png) [@ben-duchy](https://community.hubspot.com/u/ben-duchy)\
**Post date:** [September 21, 2020, 10:31am UTC](https://community.hubspot.com/t/more-or-less-than-on-dates/25535/8 "2020-09-21T10:31:13Z")

</div>

Thanks @Kevin-C thats now working, although I had to swap out ‘elif’ for ‘else’ (not sure why that would make a difference).
