Python printing a timedelta as seconds

I have two datetime.datetime objects.  When I take the difference between them I get a timedelta object.

When I print the timedelta object, it prints as hh:mm:ss:ms

I would like to convert the timedelta to simply the total number of seconds and print that, however timedelta does not have the strftime capability.

How do I convert the timedelta to simply the total number of seconds?

Thanks.

JohnSantaFeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JohnSantaFeAuthor Commented:
I should have said I want to print the total number of seconds and the milliseconds.

Thanks.
0
gelonidaCommented:
assume d is your timedelta

d_inseconds = d.days * 60 * 60 * 24 + d.seconds + d.microseconds / 1e6
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JohnSantaFeAuthor Commented:
Ah, it wasn't clear that there are really only days, seconds, and microseconds in a timedelta.  There's no need to worry about the hours and minutes.
Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Python

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.