Difference between dates

Does anyone know if it’s possible to display the difference between 2 sets of dates within HubDB?

So for example if I create 2 date columns, is there any HubL math operators that can calculate how many days difference there are?

Hiya @ben-duchy !

Does it have to be hubl? Will a js solution work

Hi @dennisedson,

I don’t think JS would work in this case as the data is being stored in HubDB and I’m not sure if you can pull data in from this using JS. Also I’m more comfortable with HubL over JS.

Thanks anyway

Hi Ben,

I did this to get the length of an event (i.e. difference between two dates):

{% if row.end_datetime %}
 {% set end_time = unixtimestamp(row.end_datetime) %}
 {% set start_time = unixtimestamp(row.start_datetime) %}
 {# get length in hours #}
 {% set length = (end_time - start_time)//60//60//1000 %}
 {% if length > 24 %}
 {% set length = length/24 %}
 {% set days = length|round(0, 'floor') %}
 {% set length = days~' days' %}
 {% elif length > 12 %}
 {% set length = 'All day event' %}
 {% elif length == 1 %}
 {% set length = length~' hour' %}
 {% elif length < 1 %}
 {% set length = (end_time - start_time)//60//1000 %}
 {% set length = length~' minutes' %}
 {% else %}
 {% set length = length~' hours' %}
 {% endif %}
{% endif %}

Hi @piersg, thanks I’ll give it a go

You just need this to get difference in days really:

{% set end_time = unixtimestamp(row.end_datetime) %}
{% set start_time = unixtimestamp(row.start_datetime) %}
{% set days = (end_time - start_time)//24//60//60//1000 %}

@piersgyou’re a genius! Thank you so much!

No worries, glad I could help :slightly_smiling_face:

Hi there, we have built an app for the marketplace that allows you to automatically calculate the time between 2 dates. Feel free to check it out here: HubSpot Marketplace