Getting the difference between two times in Python

Get the difference between two times in PythonThis post is quite the short one, but if you ever need the duration/difference between two times, this can come in very handy. But the code may be confusing. So bear with me.

So if you can get the total amount of seconds, which to make it easier, I used the package ‘arrow’.

Here’s my code, a more stripped down version than what I use.

So lets say I wanted the exact length of time(in days + rest) since ElectroCode began.

And while I know the date was January 20th 2012, I don’t exactly know the exact time, so we’ll use Noon(12 00 00)

Now if I wanted to make that able to parse weeks and years, so now I’ll add a few additions to the secondsToText() method.


So with those changes, I now get

If you think there should be changes to this post, leave a comment down below! I can’t improve if there’s no response of what I need to improve on.

See here for other ways to contact me.

Customer Service by day, Programmer by night, he’s… Iota

Looking to be a freelance IT tech of sorts, email me if you need something set up or whatever you have.