MongoDB ObjectId ↔ Timestamp Converter

Every MongoDB ObjectId automatically encodes its creation timestamp within the first 4 bytes. This powerful feature enables time-based queries and document ordering.
While MongoDB provides getTimestamp() method to extract timestamps from ObjectIds, creating ObjectIds from specific timestamps requires custom implementation for date-range queries and data analysis.
Our advanced converter instantly transforms timestamps into MongoDB ObjectIds and vice versa, perfect for database administrators, developers, and data analysts.

MongoDB ObjectId

(Important: Generated ObjectIds are for querying purposes only - not for creating new documents as they lack uniqueness guarantees)

Ready-to-use ObjectId for mongo shell queries

Time (UTC)

Year (4 digits)
Month (1 - 12)
Day (1 - 31)
Hour (0 - 23)
Minute (0 - 59)
Second (0 - 59)
ISO Timestamp

When to generate ObjectIds from timestamps?

Find all user comments created after November 1st, 2013:

db.comments.find({_id: {$gt: ObjectId("5272e0f00000000000000000")}})

Javascript functions

var objectIdFromDate = function (date) {
    return Math.floor(date.getTime() / 1000).toString(16) + "0000000000000000";
};
            
var dateFromObjectId = function (objectId) {
    return new Date(parseInt(objectId.substring(0, 8), 16) * 1000);
};