Filter HubDB data based on today's date

SOLVE
Regular Contributor

I am using HubDB to display a list of webinars.

I use the following columns:

event_start_date = start date of the event

event_end_date = end date of the event

landing_page_url = desination URL

 

However, I would not like to display past webinars.

So I need to retreive today's date and make sure that only future events are displayed.

Can I filter these in my overview?

 

My current code is below.

 

 

 

{% set queryparam = "&orderBy=event_start_date" %}

{% set table = hubdb_table_rows(671918, queryparam ) %}
{% if table == [] %}
     <p class='lead'>Sorry, no webinars available.</p>
{% else %}
     <ul> 
          {% for row in table %}
          <li>
               <h2><a href="{{ row.landing_page_url }}">{{ row.hs_name }}</a</h2>                      
          </li>
          {% endfor %}
     </ul>
{% endif %}

 

1 Accepted solution

Accepted Solutions
Highlighted
Regular Contributor

Hi Sven,

you must put inside your for cycle this strings:

{% if (row['event_start_date']|datetimeformat('%j')) >= (local_dt|datetimeformat('%j')) %}

your rows like <li>...</li>

{% endif %}

note that %j is needed to convert my date (in date format and not datetime) in a timestamp so it's possible to compare two dates

This string hide the past events

I hope this can help you

Best regards

Giovanni

 

7 Replies 7
Highlighted
Regular Contributor

Hi Sven,

you must put inside your for cycle this strings:

{% if (row['event_start_date']|datetimeformat('%j')) >= (local_dt|datetimeformat('%j')) %}

your rows like <li>...</li>

{% endif %}

note that %j is needed to convert my date (in date format and not datetime) in a timestamp so it's possible to compare two dates

This string hide the past events

I hope this can help you

Best regards

Giovanni

 

Top Contributor

@giozua - It appears that string of code works if the event dates are within the same year (ex. past 2018 events don't show up), but any events with dates in the year 2017 are showing up in the listing (and shouldn't be). Any idea how to get around this or why this is happening?

 

This is my string of code...

{% if (row['event_date_start']|datetimeformat('%j'))>=(local_dt|datetimeformat('%j'))%}

Top Contributor

Can anyone help with this? It appears that new 2019 event dates are not showing up either with that string of code. Please help!

Reply
0 Upvotes
Community Manager

Hi @leckerman,

 

I want to see if other HubDB users are experiencing this issue @Jlamb1 and @stefan are you experiencing the same thing? Do you have any tips for @leckerman?

 

Thanks,

Jenny


Did my post help answer your query? Help the Community by marking it as a solution
Reply
0 Upvotes
Top Contributor

@jennysowyrda - I was able to find help in the HubSpot slack group on Friday. Key was to add "&datetime_column__gt=0s" to the query and not use an if statement. Hope that can help someone else!

 

https://developers.hubspot.com/docs/methods/hubdb/v2/get_table_rows

Regular Contributor

Try this

{% if (row['event_date_start']|unixtimestamp)>=(local_dt|unixtimestamp)%}

It should work

 

Giovanni

New Contributor

Rather than filtering by date in your for loop, it is better to filter the query itself

 

{% set queryparam = "&orderBy=start_date" %}
{% set queryparam = queryparam + "&event_start_date__gt=" + local_dt|unixtimestamp %}
{% set table = hubdb_table_rows(XXXXXX, queryparam) %}

 

This helps in scenarios where you might only want to show a limited # of results >= today's date -- say a list of the next 3 upcoming on your homepage, not ALL upcoming.

Reply
0 Upvotes