MongoDB ObjectId Date Extractor
Extract and decode the embedded timestamp from a MongoDB ObjectId to see when a document was created
Input
Output
Readme
What is a MongoDB ObjectId?
A MongoDB ObjectId is a 12-byte (24 hex character) unique identifier used as the default _id field for every document in a MongoDB collection. Its structure is not random — it encodes meaningful information. The first four bytes store a Unix timestamp representing the second the ObjectId was created. The remaining bytes contain a random value and an incrementing counter to guarantee uniqueness even when multiple documents are inserted in the same second on the same machine.
Because the creation timestamp is baked directly into the identifier, you can determine exactly when a document was created without storing a separate createdAt field.
How the timestamp is embedded
An ObjectId like 507f1f77bcf86cd799439011 breaks down as follows:
| Bytes | Hex Characters | Purpose |
|---|---|---|
| 1–4 | 507f1f77 |
Unix timestamp (seconds since epoch) |
| 5–9 | bcf86cd799 |
Random value (unique per machine/process) |
| 10–12 | 439011 |
Incrementing counter |
Converting the first eight hex characters 507f1f77 to decimal gives 1350844279, which corresponds to 2012-10-21T21:17:59.000Z.
Tool description
This tool extracts the embedded timestamp from any valid MongoDB ObjectId and displays it in multiple date formats. Paste an ObjectId and instantly see the ISO 8601 date, UTC date, local date, and raw Unix timestamp — no database connection or code needed.
Examples
| Input ObjectId | Extracted Date (UTC) |
|---|---|
507f1f77bcf86cd799439011 |
2012-10-21T21:17:59.000Z |
65a1fc2b0000000000000000 |
2024-01-13T04:44:27.000Z |
000000000000000000000000 |
1970-01-01T00:00:00.000Z |
Features
- Instant extraction: Results appear as you type — no button clicks required
- Multiple formats: Displays ISO 8601, UTC, local date/time, and Unix timestamp
- Input validation: Rejects anything that is not a valid 24-character hex string
- No dependencies: Runs entirely in the browser with no server calls or external libraries
- Copy-ready output: Each output field can be copied individually
Use cases
- Debugging: Quickly check when a document was inserted without querying the database
- Auditing: Verify creation timestamps in exported ObjectId lists or log files
- Forensics: Determine the age of records during data migration or incident investigation
How it works
- The tool takes the first 8 hex characters of the ObjectId.
- Parses them as a 32-bit big-endian hexadecimal integer to get the Unix timestamp in seconds.
- Multiplies by 1000 and passes it to a JavaScript
Dateobject. - Formats the resulting date into ISO 8601, UTC string, locale-aware string, and raw seconds.
Limitations
- Only the creation timestamp is extracted. The random and counter portions of the ObjectId are not decoded because they do not carry user-meaningful data.
- ObjectIds generated with a custom or zero timestamp will return a valid but potentially misleading date.
- The local date format depends on your browser's locale settings.
FAQ
Can I extract a date from any MongoDB ObjectId?
Yes. Every standard MongoDB ObjectId — whether generated by the MongoDB driver, Mongoose, mongosh, or tools like Faker.js — contains a valid timestamp in its first four bytes.
Is this the same as the createdAt field?
Only if the ObjectId was generated at insertion time (the default). If a custom ObjectId was supplied manually, the embedded timestamp may differ from the actual creation time.
Does this work with ObjectIds from older MongoDB versions? Yes. The 4-byte timestamp prefix has been part of the ObjectId specification since MongoDB's initial release. The only change over time has been in the middle bytes (machine ID vs. random value), which this tool does not decode.