# Parsing or Formating Min/Max date value - For elaticsearch aggregation

**URL:** <https://discuss.elastic.co/t/parsing-or-formating-min-max-date-value-for-elaticsearch-aggregation/41834>\
**Category:** Elasticsearch\
**Created:** [February 16, 2016, 3:55am UTC](https://discuss.elastic.co/t/parsing-or-formating-min-max-date-value-for-elaticsearch-aggregation/41834 "2016-02-16T03:55:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulohss](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paulohss/32/4756_2.png) [@paulohss](https://discuss.elastic.co/u/paulohss)\
**Post date:** [February 16, 2016, 3:55am UTC](https://discuss.elastic.co/t/parsing-or-formating-min-max-date-value-for-elaticsearch-aggregation/41834/1 "2016-02-16T03:55:33Z")

</div>

I have end up here with a odd scenario. I have this aggregation to perform using Elasticsearch and c#:

```
 "aggs": {
    "Max_opened_at": {
      "max": {
        "field": "opened_at"
      }
    },
    "Min_opened_at": {
      "min": {
        "field": "opened_at"
      }
    }
  }

```

So far, so good as it is returning the aggregated keys to me as following:

```
    Response: {
  "took" : 29,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "failed" : 0
  },
  "hits" : {
    "total" : 30218,
    "max_score" : 0.0,
    "hits" : []
  },
  "aggregations" : {
    "Min_sys_created_on" : {
      "value" : 1.402508357E12,
      "value_as_string" : "1402508357000"
    },
    "Min_sys_updated_on" : {
      "value" : 1.453305924E12,
      "value_as_string" : "1453305924000"
    }

```

The problem here is the return itself. When I tried to convert the value ("1453305924000") assuming it was a Unix format using the standard conversion below, it fails due "out of range value" exception:

```
DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
return Convert.ToInt64((date - epoch).TotalSeconds);

```

I believe I've got 2 alternatives:

A) Find a way to convert this value ("1453305924000") to a understandable date format. The Unix conversion didn't worked as I said...

B) Using C#, add the "format" property in the Elastic query. It would look like this:

```
  "aggs": {
    "test": {
      "min": {
        "field": "sys_created_on", 
        "format" : "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
      }
    }

```

Unfortunately I have no idea how to do add this "format" property using NEST C#.

Any thoughts for A or B?

Thanks a lot!!

---

<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:** [July 5, 2017, 11:16pm UTC](https://discuss.elastic.co/t/parsing-or-formating-min-max-date-value-for-elaticsearch-aggregation/41834/2 "2017-07-05T23:16:11Z")

</div>


