KSUID ↔ timestamp converter
Extract the creation time from any KSUID, or generate min/max KSUIDs from a date to run range queries over sortable keys — all in your browser.
epoch timestamp shortcuts
KSUID → timestamp
date / timestamp → KSUID
Only the first 4 bytes of a KSUID encode time (seconds, UTC, offset from 2014). Use min as an inclusive lower bound and max as an inclusive upper bound for key range queries — KSUIDs sort correctly as plain strings.
How a KSUID encodes time
A KSUID (K-Sortable Unique IDentifier, from Segment) is a 20-byte identifier written as 27 characters of base62. Its first 4 bytes are a big-endian count of seconds since the KSUID epoch — 14:00:00 UTC-adjusted 1.4 billion seconds after the Unix epoch, i.e. 13 May 2014 — a deliberate offset that buys the 32-bit field headroom until the year 2150. The remaining 16 bytes are random, keeping KSUIDs generated in the same second unique. Precision is one second; milliseconds are not stored. Because the timestamp occupies the most significant bytes and base62 encoding is zero-padded to a fixed 27 characters, KSUIDs sort by creation time as plain strings — the k-sortable property in the name.
Querying KSUID keys by date
Because a KSUID's most significant bytes are its timestamp, you can
filter rows by creation date without a separate created_at
column. Generate the min KSUID (timestamp + 16 zero bytes) for the
start of your range and the max KSUID (timestamp + 16
0xff bytes) for the end, then query
WHERE id BETWEEN '<min>' AND '<max>' — both
bounds inclusive, in any store that compares keys as strings or bytes.