- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Filter HubDB data based on today's date
SOLVEAug 2, 2017 8:20 AM
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 %}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Accepted Solutions
Aug 4, 2017 12:00 PM - edited Aug 4, 2017 12:01 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Sep 27, 2019 12:40 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content