Snowflake ID to date
Discord and X IDs are snowflakes: 64-bit numbers that start with a millisecond timestamp. Paste a message, user, server or post ID to see when it was created.
Discord and X use different epochs
A snowflake keeps its timestamp in the top 42 bits (41 in X's original layout) as milliseconds since a chosen start date. Shift the ID right by 22 bits, add the epoch, and you have Unix milliseconds. The catch is that each service picks its own epoch, so the same number decodes to different dates. The decoder shows both readings and puts the more likely one first.
| Service | Epoch | Epoch in Unix ms |
|---|---|---|
| Discord | 2015-01-01T00:00:00.000Z | 1420070400000 |
| X (Twitter) | 2010-11-04T01:42:54.657Z | 1288834974657 |
Discord snowflake layout
| Bits | Field | How to read it |
|---|---|---|
| 63–22 | Timestamp: ms since the Discord epoch | (id >> 22) + 1420070400000 |
| 21–17 | Internal worker ID | (id & 0x3E0000) >> 17 |
| 16–12 | Internal process ID | (id & 0x1F000) >> 12 |
| 11–0 | Increment | id & 0xFFF |
Worked example (from Discord's documentation)
- Take the ID
175928847299117063. - Shift right by 22 bits:
41944705796milliseconds since the Discord epoch. - Add
1420070400000:1462015105796, which is 2016-04-30T11:18:25.796Z. - The remaining bits give worker 1, process 0 and increment 7.
For X, the same steps with the X epoch turn post ID 1585841080431321088 into 378093977077 + 1288834974657 = 2022-10-28T03:49:11.734Z.
Code
Snowflakes are larger than 253, so JavaScript numbers lose the last digits. Use BigInt and keep IDs as strings, as both Discord and X advise.
JavaScript
const DISCORD_EPOCH = 1420070400000n;
const X_EPOCH = 1288834974657n;
const snowflakeDate = (id, epoch) => new Date(Number((BigInt(id) >> 22n) + epoch));
snowflakeDate('175928847299117063', DISCORD_EPOCH).toISOString();
// '2016-04-30T11:18:25.796Z'
Python
from datetime import datetime, timezone
DISCORD_EPOCH = 1420070400000
def snowflake_date(snowflake: int, epoch: int = DISCORD_EPOCH) -> datetime:
return datetime.fromtimestamp(((snowflake >> 22) + epoch) / 1000, timezone.utc)
To show a time inside a Discord message rather than decode one, use the Discord timestamp builder.
Source: Discord developer docs: Snowflakes
Source: X developer docs: X IDs
Last updated: