What's the best way to store a python timedelta value in mysql?
MySQL does not offer a first class INTERVAL type, which type would be the SQL analog of python's timedelta
.
So, to store the delta, I'd suggest simply storing the difference in seconds in an integral field large enough to hold your largest expected value.
To display the delta in a "this many days, hours, minutes, etc." format — which is what you seem to be looking for — I'd suggest doing that in client code. timedelta
objects stringify nicely, or you can roll your own formatter as you like.
If you search SO for people trying to format intervals ("X seconds ago" or "X weeks ago"), you'll see relevant approaches and toolkits.