# How to convert UTC to Unix time

**URL:** <https://discuss.elastic.co/t/how-to-convert-utc-to-unix-time/104785>\
**Category:** Elasticsearch\
**Created:** [October 22, 2017, 3:02am UTC](https://discuss.elastic.co/t/how-to-convert-utc-to-unix-time/104785 "2017-10-22T03:02:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![f26227279](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/f26227279/32/21296_2.png) [@f26227279](https://discuss.elastic.co/u/f26227279)\
**Post date:** [October 22, 2017, 3:02am UTC](https://discuss.elastic.co/t/how-to-convert-utc-to-unix-time/104785/1 "2017-10-22T03:02:28Z")

</div>

the FIRST\_SWITCHED field is Unix, and when I query the range of the time I need to map the time from UTC to Unix.  
Could I have the way to convert UTC to Unix directly?  
this is my query syntax

```
GET _search
{
"_source": {
    "includes": ["FIRST_SWITCHED", "LAST_SWITCHED","IPV4_DST_ADDR","L7_PROTO_NAME","IN_BYTES","IN_PKTS","OUT_BYTES","OUT_PKTS"]
},
"query": {
"bool": {
  "must": [
    {
        "match" : { "_index" : "ntopng-2017.10.22" }
    }
    ,
    {
      "range" : {
        "FIRST_SWITCHED" : {
            "gte" : "1508478285" //how to convert it to UTC
        }
        }
    }
  ]
}
},
"aggs": {
  "IN_PKTS": {
    "sum": {
      "field": "IN_PKTS"
    }
  },
  "IN_BYTES": {
    "sum": {
      "field": "IN_BYTES"
    }
  },
  "OUT_BYTES": {
    "sum": {
      "field": "OUT_BYTES"
    }
  },
  "OUT_PKTS": {
    "sum": {
      "field": "OUT_PKTS"
    }
  }  
}   
}

```

thank you in advance

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [October 23, 2017, 8:36am UTC](https://discuss.elastic.co/t/how-to-convert-utc-to-unix-time/104785/2 "2017-10-23T08:36:08Z")

</div>

you need to store the field as a `date` in the mapping, so you can execute regular date range queries on it, without you having to do any conversion work.

See [https://www.elastic.co/guide/en/elasticsearch/reference/5.6/date.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.6/date.html)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 20, 2017, 8:36am UTC](https://discuss.elastic.co/t/how-to-convert-utc-to-unix-time/104785/3 "2017-11-20T08:36:24Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
