Find the date and time in a MongoDB ObjectId

A MongoDB ObjectId is a 12-byte identifier often used in the _id field of a MongoDB document. Its first four bytes contain a timestamp, measured in seconds since January 1, 1970, UTC (the Unix epoch).

Paste an ObjectId below to see the date stored in it. The conversion happens in your browser and does not require a connection to MongoDB.

An example ObjectId is 507c7f79bcf86cd7994f6c0e.

Convert an ObjectId to a readable date

Clear form Preferences

Accepts 24 hexadecimal characters, ObjectId("…"), or {"$oid":"…"}. Uppercase and lowercase hexadecimal letters are supported.


How does an ObjectId contain a timestamp?

The first 8 hexadecimal characters of an ObjectId store a Unix timestamp in seconds. The timestamp has one-second precision.

This is the time stored in the ID. It may differ from the document's insertion or last update time.

Get the timestamp in mongosh

ObjectId("507c7f79bcf86cd7994f6c0e").getTimestamp()
// ISODate("2012-10-15T21:26:17Z")

See the MongoDB getTimestamp documentation for details.