> For the complete documentation index, see [llms.txt](https://help.openloyalty.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.openloyalty.io/implementation-guide/integrations-and-data-exchange/expressions/sample-use-cases/set-custom-time.md).

# Set Custom Time

Expressions give you two methods to change a `DateTime` value:

* `setTime()` changes the **time** and keeps the **date** unchanged.
* `modify()` moves the **date** to a relative point in time, such as the last day of the month.

You can chain the two methods. This is useful for expiration and pending periods, date comparisons, and consistent evaluation logic in rules.

***

**🧩 Syntax**

```plaintext
(datetime).setTime(hour, minute, second)
(datetime).modify('relative format')
```

* `datetime` – a valid DateTime object, e.g. `transaction.purchasedAt`, `event.eventDate`, `member.createdAt` or `executionContext.processedAt`
* `hour` – an integer between 0 and 23
* `minute` – an integer between 0 and 59
* `second` – an integer between 0 and 59
* `relative format` – a date phrase in quotes, e.g. `'last day of this month'`, `'last day of next month'`, `'first day of next month'`, `'+7 days'`

{% hint style="info" %}
`modify()` moves the date but keeps the original time. To set the exact end of a day, chain it with `setTime(23, 59, 59)`.
{% endhint %}

***

**✅ Example Use Cases**

**Expire points at the end of the day the transaction was placed**

```plaintext
(transaction.purchasedAt).setTime(23, 59, 59)
```

**Expire points at the end of the current month**

```plaintext
executionContext.processedAt.modify('last day of this month').setTime(23, 59, 59)
```

**Expire points at the end of the next month**

```plaintext
executionContext.processedAt.modify('last day of next month').setTime(23, 59, 59)
```

For example, units granted on 28 September expire on 30 September at 23:59:59 with the first expression, and on 31 October at 23:59:59 with the second.

{% hint style="info" %}
`executionContext.processedAt` is the moment the campaign processes the member. This makes it a good base date for automation campaigns. For transaction campaigns, you can use `transaction.purchasedAt` instead.
{% endhint %}

You can use these expressions to create a dynamic configuration for the expiration or pending periods in your campaigns:

<figure><img src="https://2658975168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcNVX03KZzmrGwJihLiEx%2Fuploads%2FkQMkHffK8C5JM9bHKZzU%2Fimage.png?alt=media&#x26;token=a1e423e7-1422-4337-9bf2-b82b7fbabb63" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
Dates are calculated in the tenant's timezone. Before you go live, check that 23:59:59 matches when members expect their units to expire.
{% endhint %}

***

**🧪 Tip**

You can also combine `setTime()` with helper functions like `add_days_to_date`, `add_months_to_date`, or `add_years_to_date`. For example, to expire units at the end of the day 30 days after the transaction:

```plaintext
add_days_to_date(transaction.purchasedAt, 30).setTime(23, 59, 59)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://help.openloyalty.io/implementation-guide/integrations-and-data-exchange/expressions/sample-use-cases/set-custom-time.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `build a script that syncs our docs to a CMS` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
