# Watcher: How to convert the execution\_time to epoch time

**URL:** <https://discuss.elastic.co/t/watcher-how-to-convert-the-execution-time-to-epoch-time/105569>\
**Category:** Elasticsearch\
**Created:** [October 27, 2017, 12:43pm UTC](https://discuss.elastic.co/t/watcher-how-to-convert-the-execution-time-to-epoch-time/105569 "2017-10-27T12:43:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mruthyu](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@mruthyu](https://discuss.elastic.co/u/mruthyu)\
**Post date:** [October 27, 2017, 12:43pm UTC](https://discuss.elastic.co/t/watcher-how-to-convert-the-execution-time-to-epoch-time/105569/1 "2017-10-27T12:43:15Z")

</div>

How to convert "execution\_time" : "2017-10-27T07:09:14.666Z" of watcher to unix epoch time so that the converted epoch time can be used in the action.

---

<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 27, 2017, 2:56pm UTC](https://discuss.elastic.co/t/watcher-how-to-convert-the-execution-time-to-epoch-time/105569/2 "2017-10-27T14:56:12Z")

</div>

can you create some context around your question? Where do you want to access this? Can you share your watch and examples? Thanks

---

<div class="post-metadata">

**Author:** ![mruthyu](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@mruthyu](https://discuss.elastic.co/u/mruthyu)\
**Post date:** [November 7, 2017, 8:49am UTC](https://discuss.elastic.co/t/watcher-how-to-convert-the-execution-time-to-epoch-time/105569/3 "2017-11-07T08:49:53Z")

</div>

Using webhook action in the Watcher module to send the alert to the external ticketing system, when greater than n number of errors are found in the logs. While doing so the external system requires certain parameters needs to be sent as part of RESTful HTTP Post request. One of them is the execution\_time which needs to be in epoch time. So the watch payload execution\_time date time field needs to be converted to unix epoch time.

---

<div class="post-metadata">

**Author:** ![mruthyu](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@mruthyu](https://discuss.elastic.co/u/mruthyu)\
**Post date:** [November 8, 2017, 12:19pm UTC](https://discuss.elastic.co/t/watcher-how-to-convert-the-execution-time-to-epoch-time/105569/4 "2017-11-08T12:19:49Z")

</div>

I am also alternatively checking if the execution\_time (as in the watcher response) can be sent as is to the external system. instead of converting it to unix epoch time.

---

<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:** [November 10, 2017, 9:20am UTC](https://discuss.elastic.co/t/watcher-how-to-convert-the-execution-time-to-epoch-time/105569/5 "2017-11-10T09:20:26Z")

</div>

you can call `ctx.execution_time.getMillis()` in a painless transform script before your action and thus get the milliseconds since the epoch.

---

<div class="post-metadata">

**Author:** ![mruthyu](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@mruthyu](https://discuss.elastic.co/u/mruthyu)\
**Post date:** [November 16, 2017, 6:18am UTC](https://discuss.elastic.co/t/watcher-how-to-convert-the-execution-time-to-epoch-time/105569/6 "2017-11-16T06:18:45Z")

</div>

Great. Thank you. Will try this.

---

<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:** [December 14, 2017, 6:18am UTC](https://discuss.elastic.co/t/watcher-how-to-convert-the-execution-time-to-epoch-time/105569/7 "2017-12-14T06:18:51Z")

</div>

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