Skip to content

Instantly share code, notes, and snippets.

@onepointconsulting
Created May 4, 2022 09:01
Show Gist options
  • Save onepointconsulting/a50adcde8286b9054d5d660b98239578 to your computer and use it in GitHub Desktop.
Save onepointconsulting/a50adcde8286b9054d5d660b98239578 to your computer and use it in GitHub Desktop.
#######################################################
### Converts MongoDB timestamps to human readable dates
#######################################################
import sys
from datetime import datetime
args = sys.argv[1:]
if len(args) < 1:
print("Please enter the MongoDB ids you want to convert to timestamp")
sys.exit()
def dateFromObjectId(objectId):
seconds = int(objectId[:8], base=16)
return datetime.fromtimestamp(seconds).strftime('%Y-%m-%d %H:%M:%S')
for arg in args:
print(arg, dateFromObjectId(arg))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment