Skip to content

Instantly share code, notes, and snippets.

@daryltucker
Created September 4, 2013 17:33
Show Gist options
  • Save daryltucker/6440158 to your computer and use it in GitHub Desktop.
Save daryltucker/6440158 to your computer and use it in GitHub Desktop.
Creating a [decent] ObjectId for a previous time in python.
import datetime
from bson import ObjectId
pastDate = datetime.datetime(2013, 9, 4, 0, 57, 12, 35683)
ob = ObjectId()
obx = ObjectId().from_datetime(pastDate)
# Here it is:
pastId = ObjectId(str(obx)[:8] + str(ob)[8:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment