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

> Tweet IDs are Snowflake IDs: shift right 22 bits and add X's epoch, 1288834974657 ms, to get the posting time to the millisecond. Worked example, code, and the pre-2010 exception.

Canonical page: https://okdata.online/answers/x-tweet-id-timestamp/

**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](/apis/x/posts/get/) 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

```python
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](/answers/ai-agent-read-tweet-from-link/).

## Endpoints used

- [X post detail](https://okdata.online/apis/x/posts/get/) `x.posts.get`: $0.0003 per call

## More about X (Twitter)

- [X (Twitter) API](https://okdata.online/apis/x/)
- [How to search X (Twitter) posts by keyword and export them](https://okdata.online/guides/x-search-posts-by-keyword/)
- [How to record X (Twitter) trends for several countries every day](https://okdata.online/guides/x-trends-by-country/)
- [How fresh is the data from a social media API?](https://okdata.online/answers/how-fresh-is-social-media-api-data/)
- [How do I track clip views on TikTok, YouTube Shorts, Instagram Reels and X to pay clippers per 1,000 views?](https://okdata.online/answers/clipper-payout-view-tracking/)
- [How do I get all the replies and quote tweets of a tweet?](https://okdata.online/answers/export-x-post-replies-quotes/)
- [How can Claude or another AI agent read a tweet from an x.com link?](https://okdata.online/answers/ai-agent-read-tweet-from-link/)
- [How do I get the view count of any tweet through an API?](https://okdata.online/answers/tweet-view-count-api/)
- [twscrape says No active accounts and my X accounts keep getting locked. What now?](https://okdata.online/answers/twscrape-no-active-accounts/)
- [Official platform APIs vs third-party data APIs (2026)](https://okdata.online/compare/official-apis-vs-data-apis/)
- [How to choose a social media data API (2026)](https://okdata.online/compare/social-media-data-apis/)
- [Post detail API](https://okdata.online/roles/posts-get/)
- [X trending topics: today’s list](https://okdata.online/tools/hot-search/x/)

## Sources

- [X API docs: X IDs (64-bit Snowflake IDs)](https://docs.x.com/fundamentals/x-ids) (read 2026-11-12)
- [X API data dictionary: Post and user fields](https://docs.x.com/x-api/fundamentals/data-dictionary) (read 2026-11-12)
- [Snowflake ID (Wikipedia)](https://en.wikipedia.org/wiki/Snowflake_ID) (read 2026-11-12)
- [twitter-archive/snowflake](https://github.com/twitter-archive/snowflake) (read 2026-11-12)
- [TweetedAt: finding tweet timestamps for pre and post Snowflake tweet IDs](https://ws-dl.blogspot.com/2019/08/2019-08-03-tweetedat-finding-tweet.html) (read 2026-11-12)

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

- https://devcommunity.x.com/t/how-do-i-extract-an-id-from-a-timestamp/184282
- https://devcommunity.x.com/t/convert-tweet-time-status-to-php-for-use-in-if-else-statement/16946
- https://stackoverflow.com/questions/29754885

Updated 2026-11-12
