# Can ctx.execution\_time be formatted in Watcher?

**URL:** <https://discuss.elastic.co/t/can-ctx-execution-time-be-formatted-in-watcher/212258>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [December 18, 2019, 4:14am UTC](https://discuss.elastic.co/t/can-ctx-execution-time-be-formatted-in-watcher/212258 "2019-12-18T04:14:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shaw](https://avatars.discourse-cdn.com/v4/letter/s/5e9695/32.png) [@Shaw](https://discuss.elastic.co/u/Shaw)\
**Post date:** [December 18, 2019, 4:14am UTC](https://discuss.elastic.co/t/can-ctx-execution-time-be-formatted-in-watcher/212258/1 "2019-12-18T04:14:29Z")

</div>

Hi,

I setup a Watcher and want to have a timestamp on email subject line, so I put ctx.execution\_time, any way to format the ctx.execution\_time like "2019-12-18 08:15 PM" or similar format date/time? Please advise.

_ **Current result from my Watcher** _  
Email Subject: Alert at 2019-12-18T03:47:14.683759Z

"actions": {  
"send\_email": {  
"email": {  
"from": "...",  
"to": "...",  
"subject": "Alert at {{ctx.execution\_time}}",  
"body": {  
"html": "..."  
}  
}  
}  
}

---

<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:** [December 18, 2019, 8:49am UTC](https://discuss.elastic.co/t/can-ctx-execution-time-be-formatted-in-watcher/212258/2 "2019-12-18T08:49:13Z")

</div>

You can use a [script transform](https://www.elastic.co/guide/en/elasticsearch/reference/7.5/transform-script.html) within the action to create a new field with a formatted date.

---

<div class="post-metadata">

**Author:** ![Shaw](https://avatars.discourse-cdn.com/v4/letter/s/5e9695/32.png) [@Shaw](https://discuss.elastic.co/u/Shaw)\
**Post date:** [December 19, 2019, 2:50am UTC](https://discuss.elastic.co/t/can-ctx-execution-time-be-formatted-in-watcher/212258/3 "2019-12-19T02:50:37Z")

</div>

Thank you @spinscale, I am able to do something like this, and will test more options.

"transform" : {  
"script" : "return ['time' : ctx.execution\_time.getYear()+'-'+ctx.execution\_time.getMonth()+'-'+ctx.execution\_time.getDayOfMonth()]"  
}

---

<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:** [December 19, 2019, 9:09am UTC](https://discuss.elastic.co/t/can-ctx-execution-time-be-formatted-in-watcher/212258/4 "2019-12-19T09:09:17Z")

</div>

great you got it working. you may want to take a look at explicit formatting in order to ensure you have two or four digit long numbers (think january first)...

---

<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:** [January 16, 2020, 9:09am UTC](https://discuss.elastic.co/t/can-ctx-execution-time-be-formatted-in-watcher/212258/5 "2020-01-16T09:09:26Z")

</div>

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