Last active
September 6, 2023 02:47
-
-
Save jerblack/2656855a466cc86762b635c49dfca425 to your computer and use it in GitHub Desktop.
Convert a Postgres style timestamp to a datetime object in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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