CMS Development

SvenVanbrabant
Colaborador

Filter HubDB data based on today's date

resolver

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 %}

 

2 Soluciones aceptadas
giozua
Solución
Colaborador | Partner nivel Platinum
Colaborador | Partner nivel Platinum

Filter HubDB data based on today's date

resolver

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

 

Ver la solución en mensaje original publicado

jasonvanpelt
Solución
Participante

Filter HubDB data based on today's date

resolver

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.

Ver la solución en mensaje original publicado

9 Respuestas 9
jasonvanpelt
Solución
Participante

Filter HubDB data based on today's date

resolver

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.

fawadsabri
Colaborador

Filter HubDB data based on today's date

resolver

Hi @jasonvanpelt, so i tried the cod and it works perfectkly. However i am not able to show the events for the next 30 days. How can i add that? Thanks in advance.

0 Me gusta
giozua
Solución
Colaborador | Partner nivel Platinum
Colaborador | Partner nivel Platinum

Filter HubDB data based on today's date

resolver

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

 

Subinbajra
Participante

Filter HubDB data based on today's date

resolver

Hi @giozua ,

This solution work perfect when we use '%j' in a timestamp but the thing is this condition doesnot show up the events for next year. I mean this condition only shows the events till Dec 31, 2020. If we set the event date for Jan 01, 2021 then, the events are not being displayed in the site. I suppose you get what's the issue I mean.

It would be really a great help if there is any solutions regarding the issue. Thanks in advance! 

leckerman
Colaborador líder

Filter HubDB data based on today's date

resolver

@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'))%}

leckerman
Colaborador líder

Filter HubDB data based on today's date

resolver

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

0 Me gusta
jennysowyrda
Administrador de la comunidad
Administrador de la comunidad

Filter HubDB data based on today's date

resolver

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

0 Me gusta
leckerman
Colaborador líder

Filter HubDB data based on today's date

resolver

@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

giozua
Colaborador | Partner nivel Platinum
Colaborador | Partner nivel Platinum

Filter HubDB data based on today's date

resolver

Try this

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

It should work

 

Giovanni