How to convert DateTime object to SQL TIMESTAMP in python

Viewed 780

I have a datetime object that I want to INSERT in an SQL database TIMESTAMP column.

However, the procedure always fails due to formatting mismatch.

The datetime object:

date = datetime.datetime.strptime('2021-07-21 00:00:00', '%Y-%m-%d %H:%M:%S')

I tried to format it this way:

datetime.datetime.timestamp(date)

But it didn't work out, I think because the timestamp() function returns a float.

Is there a way to properly convert the datetime object to timestamp?

0 Answers
Related