Skip to content Skip to sidebar Skip to footer

Django: What's The Best Field Type To Represent Time Elapsed?

I'm need to save the time that some task took to the user to finish it. For example, suppose you have to answer a couple of questions of an exam. If you started at 10:00 am and fin

Solution 1:

An integral field storing seconds is probably best for storing durations (it's easy to then plug that into a timedelta). Of course, if you think you might want to store fractions of a second in the future, you might want to consider making it a float field instead.

You could also subclass either IntegerField or FloatField and make a version that automatically translates the contents to and from a timedelta automatically... or use one that someone's created already.

Post a Comment for "Django: What's The Best Field Type To Represent Time Elapsed?"