There are situations where you want to display a number of days until particular date or to display some content before or after the date has passed.
Here is a short HUBL macro that will do this for you:
HubSpot HubL
{#
Prints out a number of days until the specified date
@target_date: Date as "DD/MM/YY" (format output of a date picker field in HubSpot)
#}
{% macro days_until_date(target_date) %}
{% set date_parts = target_date|split("/") %}
{% set year = date_parts[2]|int + 2000 %}
{% set month = date_parts[1] %}
{% set day = date_parts[0] %}
{% set date_interim_format = year ~ "-" ~ month ~ "-" ~ day ~ "T00:00:00+0000" %}
{% set date_object = date_interim_format|strtotime("yyyy-MM-dd'T'HH:mm:ssZ") %}
{{ date_object|between_times(local_dt, "days") }}
{% endmacro %}
{#
Usage Examples
#}
{% set custom_date = "22/04/29" %}
There are {{ days_until_date(custom_date)|trim }} days before the {{ custom_date }}
{% set days_until = days_until_date(custom_date)|trim %}
{% if days_until > 0 %}
Date has passed!
{% endif %}
{#
Notes:
* Don't forget to "trim" the macro output, so as to get rid of the spaces!
* Macro will print a negative number before the specified date
* Macro will print a positive number after the specified date
#}