MongoDB ObjectId to timestamp
First 4 bytes read as seconds since the Unix epoch: the ObjectId's creation time (whole seconds only).
Every MongoDB ObjectId begins with its own creation time: the first 4 of its 12 bytes are a Unix timestamp in seconds. That means any document whose _id is an ObjectId carries a free created-at field. Paste one below to read it.
Detected: MongoDB ObjectId
Your timezone
UTC · GMT+00:00 · UTC
Wed, Oct 17, 2012, 09:13:27 PM
Common formats
UTC
Wed, Oct 17, 2012, 09:13:27 PM
ISO 8601
2012-10-17T21:13:27.000Z
Unix (seconds)
1350508407
Unix (millis)
1350508407000
Relative
…
World clock
Los Angeles PDT
Wed, Oct 17, 2012, 02:13:27 PM
GMT-07:00
Chicago CDT
Wed, Oct 17, 2012, 04:13:27 PM
GMT-05:00
New York EDT
Wed, Oct 17, 2012, 05:13:27 PM
GMT-04:00
London BST
Wed, Oct 17, 2012, 10:13:27 PM
GMT+01:00
Paris CEST
Wed, Oct 17, 2012, 11:13:27 PM
GMT+02:00
Kolkata IST
Thu, Oct 18, 2012, 02:43:27 AM
GMT+05:30
Shanghai CST
Thu, Oct 18, 2012, 05:13:27 AM
GMT+08:00
Tokyo JST
Thu, Oct 18, 2012, 06:13:27 AM
GMT+09:00
Sydney AEDT
Thu, Oct 18, 2012, 08:13:27 AM
GMT+11:00
Do it with the API
curl https://parsetime.dev/api/t/507f1f77bcf86cd799439011?format=objectidThe same conversion as JSON: no key, no signup, permissive CORS. Try this call or read the API docs.
Common questions
- How do I get the timestamp from an ObjectId in the mongo shell?
- ObjectId("507f1f77bcf86cd799439011").getTimestamp() returns it as an ISODate. Drivers expose the same thing: bson.ObjectId.generation_time in Python, ObjectId.getTimestamp() in Node.
- Can I rely on ObjectId time as a created-at field?
- Mostly. It's assigned by whichever client generated the id, so clock skew between app servers shows up in it, and it only has whole-second precision. For anything that matters, store an explicit createdAt. For debugging and back-of-envelope queries, though, it's excellent.
- Can I query MongoDB by date range using _id?
- Yes. Construct an ObjectId whose first 4 bytes encode your boundary timestamp and the rest are zeros, then use it in $gte/$lt comparisons. This is a standard trick for time-range scans without a separate indexed date field.