TinyBenchTools ← All tools

MongoDB ObjectId to Date Converter

The first 4 bytes of every ObjectId are the seconds since the Unix epoch when the document was inserted. That makes the humble _id field a free creation date for the millions of MongoDB documents that were saved without one.

Convert ObjectIds in bulk

FAQ

How do I get the date from an ObjectId manually?

Take the first 8 hex characters, parse them as a hexadecimal integer — that is seconds since 1970-01-01 UTC. Multiply by 1000 for a JavaScript-style millisecond timestamp.

Is the ObjectId timestamp the document creation time?

It is the moment the ObjectId was generated, which in practice is when the document was created on the client that inserted it. If an app supplies its own _id values, all bets are off.

Why does the tool warn about 24-hex strings?

Hashes, keys and other data can also be 24 hex characters. The tool decodes them as ObjectIds on a best-effort basis, which is why the toggle to exclude them exists.