PostgreSQL 18 reference · UUID Functions
PostgreSQL UUID_EXTRACT_TIMESTAMP() Function
Return the creation time stored inside a version 1 or 7 UUID, or NULL for other versions. Added in PostgreSQL 17.
PostgreSQL 18 Since 17
Syntax
uuid_extract_timestamp(uuid) | uuid_extract_version(uuid)
Parameters
| Parameter | Description |
|---|---|
uuid |
A UUID. |
Return value
timestamptz (or the version as smallint).
Examples
SELECT uuid_extract_timestamp('019a0b6c-4e00-7000-8000-000000000000') AS created;
Output
created ---------------------------- 2025-10-22 10:17:18.592+00 (1 row)
Run this on your computer — see “Get Started” for setup.
SELECT uuid_extract_version(gen_random_uuid()) AS v4, uuid_extract_timestamp(gen_random_uuid()) AS no_time;
Output
v4 | no_time ----+--------- 4 | NULL (1 row)
Run this on your computer — see “Get Started” for setup.
Version history
| Version | Change |
|---|---|
| PostgreSQL 17 | Added |
Related
UUIDV7()· Generate a version 7 UUID, which starts with a timestamp so new IDs sort in creation order. Added in PostgreSQL 18.GEN_RANDOM_UUID()· Generate a random version 4 UUID. Since PostgreSQL 18, uuidv4() is another name for it.- SQL String Functions · tutorial