# Add interval to date does not work anymore

**URL:** <https://community.cratedb.com/t/add-interval-to-date-does-not-work-anymore/1413>\
**Category:** SQL\
**Created:** [March 15, 2023, 7:10am UTC](https://community.cratedb.com/t/add-interval-to-date-does-not-work-anymore/1413 "2023-03-15T07:10:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andreas\_Vogler](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/andreas_vogler/32/741_2.png) [@Andreas\_Vogler](https://community.cratedb.com/u/Andreas_Vogler)\
**Post date:** [March 15, 2023, 7:10am UTC](https://community.cratedb.com/t/add-interval-to-date-does-not-work-anymore/1413/1 "2023-03-15T07:10:43Z")

</div>

Hi,

After upgrading from 5.1.x to 5.2.4 adding an interval to a date does not work anymore. I really think this has been working with 5.1.x.

UnsupportedFeatureException[Unknown function: (curdate() + (e.ts - date\_trunc(‘day’, e.ts))), no overload found for matching argument types: (date, interval).

e.ts is a timestamp with timezone.

The full query…

```auto
SELECT to_char(e.ts, 'DD.MM.YYYY') as day, 
  CURRENT_DATE + (e.ts - date_trunc('day', e.ts)) AS time, 
  COUNT(e.value) OVER (PARTITION BY DATE_TRUNC('day', e.ts) ORDER BY e.ts) AS acc
FROM events AS e
WHERE e.ts > current_date - 20 * 1000*60*60*24
AND e.tag = 'Gas.Signal'
AND e.value = 0 

```

---

<div class="post-metadata">

**Author:** ![Andreas\_Vogler](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/andreas_vogler/32/741_2.png) [@Andreas\_Vogler](https://community.cratedb.com/u/Andreas_Vogler)\
**Post date:** [March 15, 2023, 7:25am UTC](https://community.cratedb.com/t/add-interval-to-date-does-not-work-anymore/1413/2 "2023-03-15T07:25:47Z")

</div>

sorry, I was wrong, it also does not work with 5.1.x in that way.

solution is to convert the date to a timestamp: CURRENT\_DATE::TIMESTAMP.

```auto
SELECT to_char(e.ts, 'DD.MM.YYYY') as day, current_date::timestamp + (e.ts - date_trunc('day', e.ts)) AS time, COUNT(e.value) OVER (PARTITION BY DATE_TRUNC('day', e.ts) ORDER BY e.ts) AS acc
FROM events AS e
WHERE e.ts > current_date::timestamp - interval '20 days'
AND e.tag = 'Gas.Signal'
AND e.value = 0 

```

seems I have copied the query from PostgresSQL…

---

<div class="post-metadata">

**Author:** ![proddata](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/proddata/32/1379_2.png) [@proddata](https://community.cratedb.com/u/proddata)\
**Post date:** [March 15, 2023, 8:32am UTC](https://community.cratedb.com/t/add-interval-to-date-does-not-work-anymore/1413/3 "2023-03-15T08:32:55Z")

</div>

There was a change in 5.2 related to the subtraction of timestamps

In 5.1 and earlier `timestamp` - `timestamp` also returned a `timestamp`  
From 5.2 `timestamp` - `timestamp` returns an `interval` (following PostgreSQL)

So some behaviours might change.
