0

Is it a bad idea to store a unix time stamp as an integer and simply convert it to datetime when needed in Django ?

I found the UnixDateTimeField field from the django-unixdatetimefield package, but I don't see the benefit. You can also override the pre_save method on the DateTimeField but it adds unecssary complexity.

the above mentioned methods are found at this link: django - make datetimefield accept unix timestamp

Aran Freel
  • 3,085
  • 5
  • 29
  • 42
  • the only limitation is that the unix timestamp can be stored till 2038 ? – Aran Freel Aug 19 '20 at 09:40
  • *unix timestamp* is not "human-readable", which require a *conversion* to DateTime if you wish to show the value somewhere. – JPG Aug 19 '20 at 09:43
  • yes, in python that is simple `datetime.datetime.fromtimestamp()` – Aran Freel Aug 19 '20 at 09:44
  • Yes. IMHO, it is not about "simple" or "complex", it is about *"is it 'really required'" or not* – JPG Aug 19 '20 at 09:45
  • thats the question I have. Is it really required that I install a new package when I can simply use an int field and convert when needed. – Aran Freel Aug 19 '20 at 09:46
  • Depends on your *use-case*. I hope the question *"Which kind of data do you need the most time, timestamp? or datetime?"* will answer that – JPG Aug 19 '20 at 09:55

0 Answers0