In Python, how do you convert a `datetime` object to seconds?

Apologies for the simple question… I’m new to Python… I have searched around and nothing seems to be working.

I have a bunch of datetime objects and I want to calculate the number of seconds since a fixed time in the past for each one (for example since January 1, 1970).

import datetime
t = datetime.datetime(2009, 10, 21, 0, 0)

This seems to be only differentiating between dates that have different days:

t.toordinal()

Any help is much appreciated.

12 Answers
12

Leave a Comment