# EXPIREAT

> Make a key expire at a Unix time given in seconds.

URL: https://docs.hotkv.com/commands/expireat/

```
EXPIREAT key unix-time-seconds [NX | XX | GT | LT]
```

- Group: Keys
- Complexity: O(1)
- HotKV Cloud: all plans
- On-Premise: no license needed

`EXPIREAT` sets the moment `key` expires as an absolute Unix timestamp in
seconds, instead of a duration. A timestamp that is already in the past
deletes the key at once.

## Options

| Option | Effect |
| --- | --- |
| `NX` | Set the time only if the key has none. |
| `XX` | Set the time only if the key already has one. |
| `GT` | Set the time only if it is later than the current one (never for a key without a time to live). |
| `LT` | Set the time only if it is earlier than the current one (always for a key without a time to live). |

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| The time was set (or the key was deleted) | Integer `1` | Integer `1` |
| The key does not exist, or an option prevented the change | Integer `0` | Integer `0` |

The error replies are the same as for [EXPIRE](https://docs.hotkv.com/commands/expire/index.md), with
`'expireat'` in the invalid-time message.

## Examples

```
127.0.0.1:6379> SET report "q3"
OK
127.0.0.1:6379> EXPIREAT report 1893456000
(integer) 1
127.0.0.1:6379> EXPIRETIME report
(integer) 1893456000
127.0.0.1:6379> EXPIREAT report 1
(integer) 1
127.0.0.1:6379> EXISTS report
(integer) 0
```

## Compatibility

Same as Redis 7 and Valkey 8. For a nanosecond timestamp, see
[NEXPIREAT](https://docs.hotkv.com/commands/nexpireat/index.md).

## See also

[PEXPIREAT](https://docs.hotkv.com/commands/pexpireat/index.md), [EXPIRE](https://docs.hotkv.com/commands/expire/index.md),
[EXPIRETIME](https://docs.hotkv.com/commands/expiretime/index.md), [NEXPIREAT](https://docs.hotkv.com/commands/nexpireat/index.md)