FormatterHQ

MongoDB ObjectId to Timestamp

Find out when a MongoDB document was created from its _id alone. Paste ObjectIds in any form and get the date, Unix time, random value, counter and a range query.

Input TEXT
Output TEXT
Ready.

How to use the MongoDB ObjectId to Timestamp

  1. Paste one or more ObjectIds: plain hex, ObjectId("…"), Extended JSON or a whole log line.
  2. The decoder finds every 24-character hex ID automatically; click Decode to refresh.
  3. Read the creation date, Unix time, random value and counter under each ID.
  4. Copy the generated find() query to select documents created from that second onward.

Convert a MongoDB ObjectId to timestamp and date

The first four bytes of every MongoDB ObjectId store the moment it was created, in seconds since the Unix epoch. This ObjectId to timestamp decoder reads those bytes and shows the creation date in UTC, so you can tell when a document was inserted even if the collection has no createdAt field.

Example

Input:

ObjectId("507f1f77bcf86cd799439011")

Output:

507f1f77bcf86cd799439011
  Created:   2012-10-17T21:13:27.000Z
  Unix time: 1350508407
  Random:    bcf86cd799  (per-process value)
  Counter:   4427793  (0x439011)
  Query:     db.collection.find({ _id: { $gte: ObjectId("507f1f770000000000000000") } })

In the tool, the Created line also shows the relative age, for example "13.9 years ago".

What each field means

  • Created / Unix time: hex digits 1–8 as seconds since 1970, shown as an ISO 8601 date.
  • Random: digits 9–18, a 5-byte value chosen once per client process. IDs with the same random value were very likely created by the same application instance.
  • Counter: the last 3 bytes, incremented for each new ID. Consecutive counters from the same process show the order of inserts within one second.
  • Query: an ObjectId with the same timestamp and all other bytes set to zero. Using it with $gte (or $lt) lets you filter documents by creation time using the always-indexed _id field.

Flexible input

The decoder scans your text for any 24-character hexadecimal token, so you can paste shell output, Extended JSON like {"$oid": "65f1c0a2b3d4e5f6a7b8c9d0"}, an array of IDs from an API response or a chunk of a log file. Up to 500 IDs are decoded in one go. If nothing matches, you will see a message asking for 24 hex characters.

Things to keep in mind

  • The timestamp is set by whoever generated the ID — usually the driver on the application server — so clock drift on that machine shows up here.
  • IDs created by hand or with a custom time, for example by the ObjectId generator, can carry any date.
  • Precision is one second. For millisecond-level IDs from other systems, try the Snowflake ID decoder or convert raw seconds with the Unix timestamp converter.

Privacy

Everything is decoded in your browser. The IDs you paste are not transmitted, so you can safely inspect IDs from production data.

Frequently asked questions

Can I get the creation date of a MongoDB document from its _id?
Yes, as long as the _id is an auto-generated ObjectId. Its first four bytes are the creation time in seconds, which this tool converts to a UTC date. In mongosh you can also call ObjectId("…").getTimestamp().
How do I query documents created after a certain date?
Build an ObjectId whose first 8 hex digits are the Unix seconds of that date and whose remaining 16 digits are zeros, then filter with _id: { $gte: ObjectId("…") }. The Query line in the output gives you this for each decoded ID.
Why is the time off by a few hours?
The decoder shows UTC, marked with a trailing Z. If you expected local time, convert from UTC to your time zone; the stored value itself has no time zone.
Does the ObjectId timestamp include milliseconds?
No. It only stores whole seconds, so the decoded time always ends in .000Z. Several documents inserted in the same second are distinguished by the counter bytes.

Last updated October 3, 2026

Guides

Related tools

MongoDB ObjectId Generator Generate valid 12-byte MongoDB ObjectIds for the current time or any date, as hex, ObjectId() or Extended JSON. ASN.1 Decoder Parse DER/BER ASN.1 structures from PEM, Base64 or hex into a readable tree with OID names, strings, times and integers. CSR Decoder Decode a PKCS#10 certificate signing request to check the subject, SANs, key size and signature before you send it to a CA. SAML Response Decoder Decode Base64 or deflated SAMLResponse and SAMLRequest messages into readable XML and summarise issuer, NameID, conditions and attributes. Snowflake ID Decoder Convert Twitter/X, Discord, Instagram and other Snowflake IDs to timestamps and show worker, process and sequence bits. ULID Decoder Decode ULIDs to their embedded timestamp and random part, and convert between ULID and UUID formats. QR Code Generator Create free QR codes for URLs, text, Wi-Fi, vCards, e-mail, SMS, phone numbers, locations and events. Custom colours, PNG and SVG. QR Code Reader & Scanner Scan QR codes from an image, screenshot or your camera and see the content — links, Wi-Fi passwords, contacts — safely before opening. Regex Cheat Sheet Interactive regex cheat sheet: anchors, classes, quantifiers, groups, lookarounds, flags and Unicode, with clickable examples and a flavour table. Regex Escape Escape special characters so any text can be matched literally inside a regular expression in JavaScript, PCRE, Python or Java. Regex Explainer Break a regular expression into tokens and explain each part in plain English: groups, quantifiers, classes, anchors and lookarounds. Regex Patterns Library Copy-ready regex patterns for email, phone, URL, IP, dates, numbers, UUIDs, postal codes and passwords, each with examples and a live test box.