Skip to content

Instantly share code, notes, and snippets.

@bmwant
Created August 15, 2017 07:03
Show Gist options
  • Save bmwant/9398e38f61b088d615dac5cceb6b969a to your computer and use it in GitHub Desktop.
Save bmwant/9398e38f61b088d615dac5cceb6b969a to your computer and use it in GitHub Desktop.
Mongo queries
# Get generation time from ObjectId
>>> k['_id']
ObjectId('5991ba6cd241bf1001790c26')
>>> k['_id'].generation_time
datetime.datetime(2017, 8, 14, 14, 57, 48, tzinfo=<bson.tz_util.FixedOffset object at 0x7f1beb8d9550>)
>>> k['_id'].generation_time.strftime('%H:%M')
'14:57'
>>> k['_id'].generation_time.strftime('%H:%M:%S %d/%b/%Y')
'14:57:48 14/Aug/2017'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment