For AI

Answers

How do I get a tweet's posting time from its ID?

Short answer

Shift the post ID right by 22 bits and add 1288834974657, X's Snowflake epoch in Unix milliseconds; the result is the creation time to the millisecond, computed offline for free. It holds for every post since November 2010. When you also want the text and counts, okdata X post detail returns published_at with them for $0.0003.

Every post on X has a numeric ID like 1987654321098765432, and that number carries its own timestamp. X generates IDs with Snowflake, a scheme it built in 2010: the high bits are the milliseconds since a fixed starting point, so you can read the creation time straight out of the ID.

The layout

Bits Holds
1 (top) Always 0
41 Milliseconds since the X epoch, 1288834974657 (4 November 2010, 01:42:54.657 UTC)
10 Machine number
12 Sequence within that millisecond

So: unix_ms = (id >> 22) + 1288834974657.

Worked example

Take 1987654321098765432.

  1. Shift right by 22 bits (integer division by 4,194,304): 473893718981.
  2. Add the epoch: 473893718981 + 1288834974657 = 1762728693638 milliseconds.
  3. That is 9 November 2025, 22:51:33.638 UTC, or 06:51:33 on 10 November in Beijing.

We checked the formula against a real post from an API response: the decoded time and the post's createdAt agreed to the second.

Things that trip people up

  • Precision. IDs exceed what a JavaScript number holds exactly, so Number("1987654321098765432") silently changes the last digits. Use strings for storage and BigInt for maths, as X's own documentation says.
  • Old posts. IDs from before Snowflake went live in late 2010 are small sequential numbers, and the formula gives a meaningless time for them. The largest pre-Snowflake ID the TweetedAt researchers could find is 29700859247; treat IDs up to that as undated.
  • User IDs. Accounts created in recent years also have Snowflake IDs; one we decoded landed seven seconds before the account's listed creation time. Older accounts have short IDs that do not decode.
  • Sorting. Because time is in the high bits, sorting posts by ID sorts them by time. You do not need the date column for ordering.

When to call the API

X post detail takes an ID or an x.com link and returns published_at along with the text, media, views, likes, reposts and replies.

You need Do Cost
Posting time only Decode the ID free
Time plus current engagement One detail call $0.0003
1,000 posts from a dataset 1,000 calls $0.30

Example

import os, requests
from datetime import datetime, timezone

X_EPOCH_MS = 1288834974657

def posted_at(post_id: str) -> datetime:
    ms = (int(post_id) >> 22) + X_EPOCH_MS
    return datetime.fromtimestamp(ms / 1000, tz=timezone.utc)

pid = "1987654321098765432"
print(posted_at(pid).isoformat(timespec="milliseconds"))  # 2025-11-09T22:51:33.638+00:00

body = requests.get("https://api.okdata.online/v1/x/posts/get", timeout=60,
    headers={"Authorization": f"Bearer {os.environ['OKDATA_API_KEY']}"},
    params={"id": pid, "fields": "id,published_at,metrics.views,metrics.likes"}).json()
print(body["data"]["item"] if body["code"] == "ok" else body["code"])

In JavaScript: new Date(Number((BigInt(id) >> 22n) + 1288834974657n)).

Limits

  • A deleted or protected post still decodes, but detail returns not_found for it, which is still charged as one call.
  • Each edited version of a post has its own ID (X's data dictionary lists them as edit_history_tweet_ids), so the ID of an edit dates the edit, not the original.

To read the post itself from a link, see how an AI agent can read a tweet from an x.com link.

Sources

  1. X API docs: X IDs (64-bit Snowflake IDs)docs.x.com · read
  2. X API data dictionary: Post and user fieldsdocs.x.com · read
  3. Snowflake ID (Wikipedia)en.wikipedia.org · read
  4. twitter-archive/snowflakegithub.com · read
  5. TweetedAt: finding tweet timestamps for pre and post Snowflake tweet IDsws-dl.blogspot.com · read

Where people asked this (read 2026-11-12)

Updated

Connect once, then just ask.

Every new key comes with $0.10 to try it. One sentence connects your agent.

Start free
Connect your AI

Paste this into your agent

Read https://okdata.online/agents.md and set up okdata for me; my key is in the OKDATA_API_KEY environment variable.

Claude Code, Cursor, Codex and other agents that can open a link set themselves up from it.

MCP serverhttps://api.okdata.online/mcp