Mongo ID to timestamp: how the conversion works
A MongoDB ObjectId is 12 bytes written as 24 hex characters. The first 4 bytes, the first 8 characters, hold the Unix time in seconds when the ID was generated. Reading them as a hexadecimal number gives the timestamp directly, with no lookup or database access.
For 507f1f77bcf86cd799439011, the timestamp part is 507f1f77, which is 1350508407 in decimal. That is Wednesday, October 17, 2012 at 21:13:27 UTC. The tool shows this as a full date in your chosen time zone, in UTC, as ISO 8601, as Unix seconds and milliseconds, and as an age such as "13 years ago".
ObjectId to timestamp from JSON, queries, and logs
You don't need to clean the input first. The tool picks out every 24-character hex string, whether it is bare, wrapped as ObjectId("...") or ObjectId('...'), written as Extended JSON like {"$oid": "..."}, part of a URL, or inside a log line. Upper and lower case both work, and repeated IDs are listed once.
Values that are almost an ObjectId are flagged with the reason, such as "23 of 24 characters, 1 missing" or the non-hex letters they contain, so a bad copy and paste is easy to spot. With two or more IDs you get the oldest, the newest, the time between them, and a table you can sort by creation time.
MongoDB ObjectId to timestamp, byte by byte
Under each result the ObjectId is split into its three fields, with the decimal value of each:
- Timestamp, 4 bytes: seconds since 1970-01-01 UTC, stored big-endian.
- Random value, 5 bytes: chosen once per process by the driver or server, so IDs from the same process share it.
- Counter, 3 bytes: starts at a random number and goes up by one for each new ID, which keeps IDs made in the same second unique.
Timestamp to ObjectId for date range queries
Because the time comes first, ObjectIds sort by creation time, and you can filter on _id instead of a date field. Choose a From and To time, or a quick range like Last 7 days, and the tool builds the smallest ObjectId for each second: the time in hex followed by 16 zeros.
The query uses $gte for the start and $lt for the end, so a range from midnight to midnight covers whole days without overlap. The largest ObjectId of the start second, ending in 16 f characters, is shown too for queries that need an inclusive upper bound.
MongoDB timestamp in mongosh, JavaScript, Python, Java, and Go
The code panel fills your ObjectId into short snippets: getTimestamp() and $toDate in mongosh, a no-library one-liner and the Node.js driver in JavaScript, generation_time in Python's bson package, getDate() in the Java driver, and Timestamp() in the Go driver.
MongoDB also has a BSON type called Timestamp, used internally for the replication oplog. It is not the same as an ObjectId's time or a Date. For creation or update times you store yourself, use the Date type.

