# Unable to calculate difference between dates

**URL:** <https://community.neo4j.com/t/unable-to-calculate-difference-between-dates/11209>\
**Category:** Cypher\
**Created:** [October 22, 2019, 1:33am UTC](https://community.neo4j.com/t/unable-to-calculate-difference-between-dates/11209 "2019-10-22T01:33:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![info6](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/info6/32/4097_2.png) [@info6](https://community.neo4j.com/u/info6)\
**Post date:** [October 22, 2019, 1:33am UTC](https://community.neo4j.com/t/unable-to-calculate-difference-between-dates/11209/1 "2019-10-22T01:33:23Z")

</div>

Hi

I am trying to subtract two dates, but am running into what I think are data type issues.

When I use the following statement:

```auto
RETURN apoc.date.convert(endDate - LAST_DATE, "ms", "d")

```

the following error is returned:

> Neo.ClientError.Statement.TypeError: Cannot subtract `Date` from `Long`

The data types for each are:

| apoc.meta.type(endDate) | apoc.meta.type(LAST\_DATE) |
| --- | --- |
| "INTEGER" | "LocalDate" |

endDate was created from a string:

```auto
date('2012-06-12) AS endDate

```

LAST\_DATE was created:

```auto
WITH apoc.date.parse('12/31/2018', 'y', 'MM/dd/yyyy') AS LAST_DATE

```

I haven't been able to either convert endDate using apoc.date.parse to INTEGER, or use toInteger().

I appreciate any help anyone could give.

Kind regards

---

<div class="post-metadata">

**Author:** ![lju](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/lju/32/12574_2.png) [@lju](https://community.neo4j.com/u/lju)\
**Post date:** [October 22, 2019, 10:58am UTC](https://community.neo4j.com/t/unable-to-calculate-difference-between-dates/11209/2 "2019-10-22T10:58:14Z")

</div>

Hi!

You will need to use the duration keyword to help with that. For example, if I wanted to know the number of days between 2012-04-04 and 2011-04-05, I'd write something like this:

`return duration.inDays(date("2012-04-04"), date("2011-04-05")).days`

I hope that helps!

---

<div class="post-metadata">

**Author:** ![info6](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/info6/32/4097_2.png) [@info6](https://community.neo4j.com/u/info6)\
**Post date:** [October 22, 2019, 11:31am UTC](https://community.neo4j.com/t/unable-to-calculate-difference-between-dates/11209/3 "2019-10-22T11:31:03Z")

</div>

> [@lju](#):
>
> return duration.inDays(date("2012-04-04"), date("2011-04-05")).days

Hi ljubica.lazarevic

Thanks so much ! With a bit of tweaking I got my Cypher working with your help - very happy!

Kind regards

---

<div class="post-metadata">

**Author:** ![dana\_canzano](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/dana_canzano/32/27392_2.png) [@dana\_canzano](https://community.neo4j.com/u/dana_canzano)\
**Post date:** [October 22, 2019, 1:29pm UTC](https://community.neo4j.com/t/unable-to-calculate-difference-between-dates/11209/4 "2019-10-22T13:29:24Z")

</div>

for those needing more details of the Neo4j temporal functions see [https://neo4j.com/docs/cypher-manual/3.5/functions/temporal/duration/#functions-duration-indays](https://neo4j.com/docs/cypher-manual/3.5/functions/temporal/duration/#functions-duration-indays)
