> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify-poc.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# state_at()

> Determine the state at a given time

<Icon icon="tag" iconType="duotone" /> Since [1.15.0][toolkit-1.15.0]

Determine the state at a given time from a state aggregate.

## Samples

Create a state aggregate and determine the state at a particular time.

```sql theme={"dark"}
SELECT state_at(
  (SELECT state_agg(ts, state) FROM states_test),
  '2020-01-01 00:00:05+00'
);
```

Returns:

```
state_at
----------
START
```

## Arguments

The syntax is:

```sql theme={"dark"}
state_at(
  agg StateAgg,
  ts TIMESTAMPTZ
) RETURNS TEXT

state_at_int(
  agg StateAgg,
  ts TIMESTAMPTZ
) RETURNS BIGINT
```

| Name | Type        | Default | Required | Description                                             |
| ---- | ----------- | ------- | -------- | ------------------------------------------------------- |
| agg  | StateAgg    | -       | ✔        | A state aggregate created with [`state_agg`][state_agg] |
| ts   | TIMESTAMPTZ | -       | ✔        | The time to get the state at                            |

## Returns

| Column | Type           | Description                  |
| ------ | -------------- | ---------------------------- |
| state  | TEXT \| BIGINT | The state at the given time. |

[state_agg]: /api-reference/timescaledb-toolkit/state-tracking/state_agg/state_agg

[toolkit-1.15.0]: https://github.com/timescale/timescaledb-toolkit/releases/tag/1.15.0
