Skip to content

Instantly share code, notes, and snippets.

@jerblack
Last active September 6, 2023 02:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jerblack/2656855a466cc86762b635c49dfca425 to your computer and use it in GitHub Desktop.
Save jerblack/2656855a466cc86762b635c49dfca425 to your computer and use it in GitHub Desktop.
Convert a Postgres style timestamp to a datetime object in Python
import datetime
import re
timestamp = '2019-05-15 22:37:55.276407'
def parse_timestamp(timestamp):
return datetime.datetime(*[int(x) for x in re.findall(r'\d+', timestamp)])
# returns datetime.datetime(2019, 5, 15, 22, 37, 55, 276407)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment