# Difference between dates

**URL:** <https://community.hubspot.com/t/difference-between-dates/27885>\
**Category:** CMS Development\
**Tags:** professional\
**Created:** [November 11, 2020, 5:15pm UTC](https://community.hubspot.com/t/difference-between-dates/27885 "2020-11-11T17:15:49Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ben-duchy](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/ben-duchy/32/84083_2.png) [@ben-duchy](https://community.hubspot.com/u/ben-duchy)\
**Post date:** [November 11, 2020, 5:15pm UTC](https://community.hubspot.com/t/difference-between-dates/27885/1 "2020-11-11T17:15:49Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [November 12, 2020, 4:26pm UTC](https://community.hubspot.com/t/difference-between-dates/27885/2 "2020-11-12T16:26:59Z")

</div>

Hiya @ben-duchy !

Does it have to be hubl? Will a [js solution](https://www.geeksforgeeks.org/how-to-calculate-the-number-of-days-between-two-dates-in-javascript/) work

---

<div class="post-metadata">

**Author:** ![ben-duchy](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/ben-duchy/32/84083_2.png) [@ben-duchy](https://community.hubspot.com/u/ben-duchy)\
**Post date:** [November 13, 2020, 3:11pm UTC](https://community.hubspot.com/t/difference-between-dates/27885/3 "2020-11-13T15:11:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![piersg](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/piersg/32/99782_2.png) [@piersg](https://community.hubspot.com/u/piersg)\
**Post date:** [November 12, 2020, 4:53pm UTC](https://community.hubspot.com/t/difference-between-dates/27885/4 "2020-11-12T16:53:31Z")

</div>

Hi Ben,

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

```lia-code-sample
{% 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 %}

```

---

<div class="post-metadata">

**Author:** ![ben-duchy](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/ben-duchy/32/84083_2.png) [@ben-duchy](https://community.hubspot.com/u/ben-duchy)\
**Post date:** [November 13, 2020, 3:12pm UTC](https://community.hubspot.com/t/difference-between-dates/27885/5 "2020-11-13T15:12:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![piersg](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/piersg/32/99782_2.png) [@piersg](https://community.hubspot.com/u/piersg)\
**Post date:** [November 13, 2020, 4:14pm UTC](https://community.hubspot.com/t/difference-between-dates/27885/6 "2020-11-13T16:14:01Z")

</div>

You just need this to get difference in days really:

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

```

---

<div class="post-metadata">

**Author:** ![ben-duchy](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/ben-duchy/32/84083_2.png) [@ben-duchy](https://community.hubspot.com/u/ben-duchy)\
**Post date:** [November 13, 2020, 4:24pm UTC](https://community.hubspot.com/t/difference-between-dates/27885/7 "2020-11-13T16:24:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![piersg](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/piersg/32/99782_2.png) [@piersg](https://community.hubspot.com/u/piersg)\
**Post date:** [November 13, 2020, 4:32pm UTC](https://community.hubspot.com/t/difference-between-dates/27885/8 "2020-11-13T16:32:09Z")

</div>

No worries, glad I could help 🙂

---

<div class="post-metadata">

**Author:** ![Thrive](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/thrive/32/19516_2.png) [@Thrive](https://community.hubspot.com/u/Thrive)\
**Post date:** [July 24, 2024, 12:38am UTC](https://community.hubspot.com/t/difference-between-dates/27885/9 "2024-07-24T00:38:54Z")

</div>

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](https://ecosystem.hubspot.com/marketplace/apps/marketing/data-management/calculations-3449553)
