# Calculating interval

**URL:** <https://discuss.dgraph.io/t/calculating-interval/10582>\
**Category:** Dgraph\
**Tags:** kind:question, datetime\
**Created:** [September 24, 2020, 9:52am UTC](https://discuss.dgraph.io/t/calculating-interval/10582 "2020-09-24T09:52:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![youyin123](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/youyin123/32/4685_2.png) [@youyin123](https://discuss.dgraph.io/u/youyin123)\
**Post date:** [September 24, 2020, 9:52am UTC](https://discuss.dgraph.io/t/calculating-interval/10582/1 "2020-09-24T09:52:38Z")

</div>

hi, @MichelDiz

How to calculate the interval between the date and 2020-05-21?  
I want to run code like this, but it’s error…

```auto
math(since(date) - since(2020-05-21))

```

---

<div class="post-metadata">

**Author:** ![chewxy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/chewxy/32/4339_2.png) [@chewxy](https://discuss.dgraph.io/u/chewxy)\
**Post date:** [September 25, 2020, 7:20am UTC](https://discuss.dgraph.io/t/calculating-interval/10582/2 "2020-09-25T07:20:41Z")

</div>

`since` returns the number of seconds from the time specified as a float. Are you sure that’s what you want to do?

if you want to do the number of seconds since 2020-05-21, you could just do `since(2020-05-21)`

Although I am not exactly sure what you want to do

---

<div class="post-metadata">

**Author:** ![anand](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/anand/32/5674_2.png) [@anand](https://discuss.dgraph.io/u/anand)\
**Post date:** [September 25, 2020, 9:47am UTC](https://discuss.dgraph.io/t/calculating-interval/10582/3 "2020-09-25T09:47:17Z")

</div>

Both dates has to be present as predicates for the following to work. I could not get it to work by making one of them as variables (I am assuming that was perhaps your intention).

With this mutation:

```auto
{
set{
  _:a <cdate> "2020-05-21" .
  _:a <bdate> "2019-05-21" .
}}

```

this query returns results as below

```auto
query myDemoQuery() {

  films(func: has(bdate)) {
    pastDate as bdate
    futureDate as cdate
    futureSeconds as math(since(futureDate) )
    pastSeconds as math(since(pastDate) )  
    difference: math(pastSeconds - futureSeconds )
    
  }
}

```

Result:

```auto
{
  "data": {
    "films": [
      {
        "bdate": "2019-05-21T00:00:00Z",
        "cdate": "2020-05-21T00:00:00Z",
        "val(futureSeconds)": 11007887.911656,
        "val(pastSeconds)": 42630287.911659,
        "difference": 31622400.000003
      }
    ]
  }
}

```
