# Need script to convert ISO field to Mill format

**URL:** <https://discuss.elastic.co/t/need-script-to-convert-iso-field-to-mill-format/188102>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [June 28, 2019, 7:30pm UTC](https://discuss.elastic.co/t/need-script-to-convert-iso-field-to-mill-format/188102 "2019-06-28T19:30:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DeepakBhatt](https://avatars.discourse-cdn.com/v4/letter/d/5f9b8f/32.png) [@DeepakBhatt](https://discuss.elastic.co/u/DeepakBhatt)\
**Post date:** [June 28, 2019, 7:30pm UTC](https://discuss.elastic.co/t/need-script-to-convert-iso-field-to-mill-format/188102/1 "2019-06-28T19:30:50Z")

</div>

Hi Team,

```
  We had stored one date field in ISO format (2019-06-25) but now want to convert it into Millisecond format (1561420800000), we don't have hour, min & sec information stored in the date field. We can take default (2019-06-25 00:00:00) to convert it into millisecond format.

 Can you guys help us here to write a script which can convert all the data we have in our cluster in Millisecond format.

```

Stored Date field: 2019-06-25  
Desired Date Field: 1561420800000

```
 Thanks in advanced.

```

Regards!  
Deepak Bhatt

---

<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:** [July 1, 2019, 9:23am UTC](https://discuss.elastic.co/t/need-script-to-convert-iso-field-to-mill-format/188102/3 "2019-07-01T09:23:17Z")

</div>

you can use a script processor for this

```auto
POST _ingest/pipeline/_simulate
{
  "pipeline": {
    "processors": [
      {
        "script": {
          "lang": "painless",
          "source": "ctx.epoch = LocalDate.parse(ctx.date).atStartOfDay(ZoneOffset.UTC).toInstant().toEpochMilli()"
        }
      }
    ]
  },
  "docs": [
    {
      "_source": {
        "date": "2019-06-30"
      }
    }
  ]
}

```

See the [ingest node docs](https://www.elastic.co/guide/en/elasticsearch/reference/7.2/ingest.html) for more information

---

<div class="post-metadata">

**Author:** ![DeepakBhatt](https://avatars.discourse-cdn.com/v4/letter/d/5f9b8f/32.png) [@DeepakBhatt](https://discuss.elastic.co/u/DeepakBhatt)\
**Post date:** [July 1, 2019, 3:19pm UTC](https://discuss.elastic.co/t/need-script-to-convert-iso-field-to-mill-format/188102/4 "2019-07-01T15:19:50Z")

</div>

Thanks Alexander, I have tried this on my local and is working fine will try with actual data and let you know the output. Thanks for your help.... 🙂

---

<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 29, 2019, 3:19pm UTC](https://discuss.elastic.co/t/need-script-to-convert-iso-field-to-mill-format/188102/5 "2019-07-29T15:19:51Z")

</div>

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