Advertisement

ObjectId Timestamp

Paste a MongoDB ObjectId to reveal the creation time hidden in its first 4 bytes. See the date in UTC and your local timezone, the raw Unix timestamp, and how long ago it was created.

Extract timestamp

The first 8 hex characters hold the Unix time.

Results appear here.

Advertisement

Where the timestamp lives

The first 4 bytes of an ObjectId (the first 8 hex characters) store the Unix timestamp in seconds at the moment the ID was created. This tool parses those characters as a hexadecimal integer and converts them to a human date, so you can recover when any document ID was minted without querying the database.

Why extract it

This is useful for debugging and forensics: checking when a record was created from a log line, verifying seed data, or sorting out whether an ID came from production or a test run. Note the precision is one second, and only IDs generated with a real clock carry a meaningful timestamp.

ObjectId Timestamp FAQs

What counts as a valid ObjectId?
A valid ObjectId is exactly 24 hexadecimal characters (0-9, a-f). Anything shorter, longer, or containing other characters is rejected with an error message.
How precise is the extracted time?
Only to one-second precision. The timestamp field is a 32-bit Unix time in seconds, so milliseconds are not stored. Two IDs created in the same second share the same timestamp.
Is the timestamp in UTC?
Yes, the timestamp is stored in UTC by definition. The tool shows both the UTC time and your local time so you can compare against logs in either zone.
Can the timestamp be wrong?
Only if the ID was generated with a correct system clock. Test fixtures and hand-made IDs can carry any timestamp, including the future, so treat the result as informational.
How do I do this in code?
In MongoDB shells use ObjectId("...").getTimestamp(). In Python, bson.ObjectId("...").generation_time gives a datetime. This page does the same math without any setup.
Advertisement