# Painless current date

**URL:** <https://discuss.elastic.co/t/painless-current-date/102589>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [October 3, 2017, 3:56pm UTC](https://discuss.elastic.co/t/painless-current-date/102589 "2017-10-03T15:56:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fluffierbump](https://avatars.discourse-cdn.com/v4/letter/f/e480ec/32.png) [@fluffierbump](https://discuss.elastic.co/u/fluffierbump)\
**Post date:** [October 3, 2017, 3:56pm UTC](https://discuss.elastic.co/t/painless-current-date/102589/1 "2017-10-03T15:56:25Z")

</div>

I'm trying to write a painless script that will return the current date minus 2hours in a format like this - 2017-10-03T11:42:44.279Z

Can I do this in painless?

---

<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 11, 2017, 7:36am UTC](https://discuss.elastic.co/t/painless-current-date/102589/2 "2017-10-11T07:36:52Z")

</div>

The current date can not be accessed in a script currently. but you can use the `ctx.trigger.scheduled_time` or `ctx.trigger.triggered_time` for this - this date is usually around the current date.

Substracting a date would work like this:

```auto
Instant.ofEpochMilli(ctx.trigger.scheduled_time.getMillis()).plus(Duration.ofDays(-2))

```

hope this helps

---

<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 8, 2017, 7:37am UTC](https://discuss.elastic.co/t/painless-current-date/102589/3 "2017-11-08T07:37:12Z")

</div>

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