I'm querying a PostgreSQL database with asyncpg. My query is checking a table to determine if a specific record number exist. If the record exist then the date_modified information is extracted from that record, which I need to compare with a newly collected date.
My current issue is trying to extract the timestamp information from the list, which is returned by the query, which is shown below:
[<Record date_modified=datetime.datetime(2010, 9, 9, 8, 33, 31)>]
The only way that I have found to obtain the date string is with a regex.
date_modified = re.search(r'(\d{4},\s\d{1,2},\s\d{1,2},\s\d{1,2},\s\d{1,2},\s\d{1,2})', repr(date_check))
print (date_modified.group(0))
outputs: 2010, 9, 9, 8, 33, 31
How do I convert the output above to this format?
2010-09-09 08:33:31